home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Imag / IMAGINE / CUSTOM.Z / PATTERN.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-03-27  |  23.4 KB  |  562 lines

  1. Attribute VB_Name = "modPattern"
  2. Option Explicit
  3. 'This data type is for each pass in the Hatch Pattern
  4. Type PassData
  5.     dRotation As Double
  6.     dXOrigin As Double
  7.     dYOrigin As Double
  8.     dSpacing As Double
  9.     dShift As Double
  10.     DashGap(20) As Double
  11.     DashCount As Double
  12. End Type
  13. 'this data type is for storing all the data necessary for a Hatch pattern in one variable
  14. Type HatchData
  15.     HatchName As String
  16.     HatchDescription As String
  17.     Pass(100) As PassData
  18.     NumPasses As Integer
  19. End Type
  20. Public gHatchArray(500) As HatchData
  21. Public gpatFileName As String
  22. Public gNumberOfHatches As Integer
  23. Const mCOMMENTLINE = 1
  24. Const mPATTERNNAME = 2
  25. Const mVECTORLINE = 3
  26. Const ERRORLINE = 4
  27. Public gNumItemsInGrid As Integer
  28. Public gfrmPattern As Form
  29. Public gobjBook As Object
  30. Dim mobjUnitsOfMeasure As Object
  31. Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  32. '
  33. ' This is the main module for the macro project.  It includes constants and Windows API
  34. ' declarations needed for the macro.
  35. '
  36. '
  37. ' Declare the rectangle type for use in GetWindowRect
  38. '
  39. Type RectType
  40.     iLeft As Long
  41.     iTop As Long
  42.     iright As Long
  43.     ibottom As Long
  44. End Type
  45. '
  46. ' Declare the Windows function that allows us to center a form either on the screen
  47. ' or within the application.
  48. '
  49. Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RectType) As Long
  50.  
  51. 'Declares and constant for getting the locale information
  52. Public Const LOCALE_SDECIMAL = &HE
  53. Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
  54. Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
  55.  
  56.  
  57. '
  58. ' This is the main function which is the entry point for the OLE server.
  59. ' Only initialization logic which is common to all macros in this server
  60. ' should be placed in this subroutine.
  61. '
  62. Sub main()
  63. End Sub
  64. '
  65. ' This function centers a form either on the screen if the hWndParent is 0 or within
  66. ' the parent.  Copied from VBProgrammers Journal OCT 95 and modified for our needs.
  67. '
  68. Sub CenterForm(ByVal hWndParent As Long, frmForm As Form)
  69.  
  70.     Dim iLeft As Long
  71.     Dim iTop As Long
  72.     Dim iMidX As Long
  73.     Dim iMidY As Long
  74.     Dim rcParent As RectType
  75.  
  76.     'Find the ideal center point
  77.     If hWndParent = 0 Then
  78.         ' No parent, center over the screen using the screen object
  79.         iMidX = Screen.Width / 2
  80.         iMidY = Screen.Height / 2
  81.     Else
  82.         ' Center within the form's parent
  83.         Call GetWindowRect(hWndParent, rcParent)
  84.  
  85.         ' in calculating mid x it seems to me that we should left*twipsX and right*twipsX
  86.         ' rather than right*twipsY
  87.         iMidX = ((rcParent.iLeft * Screen.TwipsPerPixelX) + _
  88.                  (rcParent.iright * Screen.TwipsPerPixelY)) / 2
  89.         iMidY = ((rcParent.iTop * Screen.TwipsPerPixelY) + _
  90.                  (rcParent.ibottom * Screen.TwipsPerPixelY)) / 2
  91.  
  92.         ' If the application is maximized or the app for some reason returns all 0 in the
  93.         ' rectangle type, then center on the screen
  94.         If (rcParent.iLeft = 0 And rcParent.iright = 0 And _
  95.             rcParent.iTop = 0 And rcParent.ibottom = 0) Then
  96.             iMidX = Screen.Width / 2
  97.             iMidY = Screen.Height / 2
  98.         End If
  99.     End If
  100.  
  101.  
  102.     ' Find the form's upper left based on that
  103.     iLeft = iMidX - (frmForm.Width / 2)
  104.     iTop = iMidY - (frmForm.Height / 2)
  105.  
  106.     ' If the form is outside the screen, move it inside
  107.     If iLeft < 0 Then
  108.         iLeft = 0
  109.     ElseIf (iLeft + frmForm.Width) > Screen.Width Then
  110.         iLeft = Screen.Width - frmForm.Width
  111.     End If
  112.  
  113.     If iTop < 0 Then
  114.         iTop = 0
  115.     ElseIf (iTop + frmForm.Height) > Screen.Height Then
  116.         iTop = Screen.Height - frmForm.Height
  117.     End If
  118.  
  119.     ' Move the form to its new position
  120.     frmForm.Move iLeft, iTop
  121. End Sub
  122. Public Function GetLineType(TextLine As String) As Integer
  123. 'This function returns one of the following types
  124. 'mCOMMENTLINE = 1
  125. 'mPATTERNNAME = 2
  126. 'mVECTORLINE = 3
  127. 'ERRORLINE = 4
  128. Dim tempstring As String
  129. Dim startLook As Integer
  130. Dim commapos As Integer
  131. Dim i As Integer
  132.     If InStr(TextLine, ";") Then
  133.         GetLineType = mCOMMENTLINE
  134.     ElseIf InStr(TextLine, "*") Then
  135.         GetLineType = mPATTERNNAME
  136.     Else
  137.         'test to see if there are four commas in the string
  138.         startLook = 1
  139.         For i = 1 To 4
  140.             commapos = InStr(startLook, TextLine, ",", 0)
  141.             If commapos = 0 Then
  142.                 Exit For
  143.             Else
  144.                 startLook = commapos
  145.             End If
  146.         Next i
  147.         If i < 4 Then
  148.             GetLineType = ERRORLINE
  149.         Else
  150.             GetLineType = mVECTORLINE
  151.         End If
  152.     
  153.     End If
  154. End Function
  155.  
  156. Public Sub CreateHatchArray()
  157. 'Parses the .pat file and fills up the gHatchData Array
  158.     Dim MyChar As String
  159.     Dim hatchnum As Integer
  160.     Dim oldhatchnum As Integer
  161.     Dim NotCR As Boolean
  162.     Dim i As Integer
  163.     Dim LineData(1000) As String
  164.     Dim tempstring As String
  165.     Dim checkstring As String
  166.     Dim teststring As String
  167.     Dim testpass As PassData
  168.     Dim passnum As Integer
  169.     Open gpatFileName For Input As #1
  170.     NotCR = True
  171.     Set mobjUnitsOfMeasure = gfrmPattern.igCommand1.Application.ActiveBook.UnitsOfMeasure
  172.     While Not EOF(1)
  173.         NotCR = True
  174.         While NotCR And Not EOF(1)
  175.             MyChar = Input(1, #1)
  176.             If MyChar = Chr(13) Then
  177.                 'check the line type
  178.                 If GetLineType(tempstring) = mPATTERNNAME Then
  179.                     'Break the line into Description and Name Parts and pass them to the
  180.                     'global structure gHatchArray
  181.                     tempstring = Right(tempstring, Len(tempstring) - 2)
  182.                     gHatchArray(hatchnum).HatchName = Left(tempstring, InStr(tempstring, ",") - 1)
  183.                     gHatchArray(hatchnum).HatchDescription = LTrim(Right(tempstring, Len(tempstring) - InStr(tempstring, ",")))
  184.                     gHatchArray(oldhatchnum).NumPasses = passnum
  185.                     oldhatchnum = hatchnum
  186.                     hatchnum = hatchnum + 1
  187.                     passnum = 0
  188.                 ElseIf GetLineType(tempstring) = mVECTORLINE Then
  189.                     '
  190.                     gHatchArray(oldhatchnum).Pass(passnum) = ParseVectorLine(tempstring)
  191.                     passnum = passnum + 1
  192.                 End If
  193.                 NotCR = False
  194.                 teststring = tempstring
  195.                 tempstring = ""
  196.             Else
  197.                 tempstring = tempstring + MyChar
  198.                 checkstring = tempstring
  199.             End If
  200.         Wend
  201.         gHatchArray(oldhatchnum).NumPasses = passnum
  202.        
  203.     Wend
  204.     'test to see if the last line grabbed when EOF marker was found was a vectorline
  205.     If GetLineType(checkstring) = mVECTORLINE Then
  206.         'add the additional line to the gHatchArray
  207.         passnum = passnum + 1
  208.         gHatchArray(oldhatchnum).Pass(passnum) = ParseVectorLine(checkstring)
  209.         gHatchArray(oldhatchnum).NumPasses = passnum
  210.     End If
  211.     Close #1
  212.     gNumberOfHatches = hatchnum - 1
  213.     Set mobjUnitsOfMeasure = Nothing
  214. End Sub
  215. Function ParseVectorLine(linestring As String) As PassData
  216. 'This Function parses a line from the .pat file which has data for 1 pass.
  217. 'It returns it as type PassData
  218.     Dim tempstring As String
  219.     Dim numstring As String
  220.     Dim testbit As Boolean
  221.     Dim dashnum As Integer
  222.     Dim temparray(20) As Double
  223.     Dim j As Integer
  224.     Dim i As Integer
  225.     Dim dashgapcount As Integer
  226.     Dim PreviousNegative As Boolean
  227.     Dim lReturnValue As Long
  228.     Dim sDecimalDelimiter As String * 10
  229.     Dim sDelimiter As String
  230.     Dim lDelimiterBuffer As Long
  231.     Dim lLocaleID As Long
  232.     Dim thickstring As String
  233.     'dRotation As Double
  234.     'dXOrigin As Double
  235.     'dYOrigin As Double
  236.     'dSpacing As Double
  237.     'dShift As Double
  238.     'DashGap(20) As Double
  239.     'DashCount As integer
  240.     tempstring = Trim(linestring)
  241.     
  242.     'Find decimal delimiter for this OS
  243.     lLocaleID = GetUserDefaultLCID
  244.     lDelimiterBuffer = Len(sDecimalDelimiter)
  245.     lReturnValue = GetLocaleInfo(lLocaleID, LOCALE_SDECIMAL, sDecimalDelimiter, lDelimiterBuffer)
  246.     
  247.     If lReturnValue = 0 Then
  248.         MsgBox "Error has occured while retrieving locale information.  Unable to continue.", vbExclamation
  249.     Else
  250.         sDelimiter = Left(sDecimalDelimiter, lReturnValue - 1)
  251.     End If
  252.    
  253.     testbit = True
  254.     With mobjUnitsOfMeasure
  255.     'loop thru 5 times to set .dRotation .dXOrigin .dYOrigin .dSpacing .dShift for ParseVectorLine
  256.         For i = 1 To 5
  257.             tempstring = Trim(tempstring)
  258.             'Sometimes there is no dashgap pattern, so we have to check for commas on the 5th pass
  259.             If InStr(tempstring, ",") Then
  260.                 numstring = Left(tempstring, InStr(tempstring, ",") - 1)
  261.             Else
  262.                 numstring = tempstring
  263.                 testbit = False
  264.             End If
  265.             
  266.             If lReturnValue <> 0 Then
  267.                 numstring = ConvertDecimalDelimiter(Trim(numstring), sDelimiter)
  268.             End If
  269.  
  270.             
  271.             tempstring = Right(tempstring, Len(tempstring) - InStr(tempstring, ","))
  272.             If i = 1 Then
  273.                 ParseVectorLine.dRotation = .ParseUnit(igUnitAngle, _
  274.                                                 numstring & " " & gfrmPattern.cmbAngle.Text)
  275.             ElseIf i = 2 Then
  276.                 ParseVectorLine.dXOrigin = .ParseUnit(igUnitDistance, _
  277.                                                 numstring & " " & gfrmPattern.cmbLength.Text)
  278.             ElseIf i = 3 Then
  279.                 ParseVectorLine.dYOrigin = .ParseUnit(igUnitDistance, _
  280.                                                 numstring & " " & gfrmPattern.cmbLength.Text)
  281.             ElseIf i = 4 Then
  282.                 ParseVectorLine.dShift = .ParseUnit(igUnitDistance, _
  283.                                                 numstring & " " & gfrmPattern.cmbLength.Text)
  284.             Else
  285.                 ParseVectorLine.dSpacing = .ParseUnit(igUnitDistance, _
  286.                                                 numstring & " " & gfrmPattern.cmbLength.Text)
  287.                 ' Enter a loop to fill up a temporary dashgap array
  288.                 ' If there are items for dashgap, check for commas so you know you've got the last item
  289.                 While testbit
  290.                     If InStr(tempstring, ",") Then
  291.                         numstring = Left(tempstring, InStr(tempstring, ",") - 1)
  292.                     Else
  293.                         numstring = tempstring
  294.                         testbit = False
  295.                     End If
  296.                     
  297.                     If lReturnValue <> 0 Then
  298.                         numstring = ConvertDecimalDelimiter(Trim(numstring), sDelimiter)
  299.                     End If
  300.                 
  301.                     temparray(dashnum) = Format(numstring)
  302.                     tempstring = Right(tempstring, Len(tempstring) - InStr(tempstring, ","))
  303.                     dashnum = dashnum + 1
  304.                 Wend
  305.                 'If there are values in temparray, further parse to fix for Imagineer's dashgap
  306.                 If dashnum <> 0 Then
  307.                     For j = 0 To dashnum - 1
  308.                         'test the value of the item in temparray entry act accordingly
  309.                         If j = 0 Then
  310.                             If temparray(0) < 0 Then 'negative
  311.                                 'Create a zero length dash
  312.                                 ParseVectorLine.DashGap(0) = 0
  313.                                 'take the absolute value and create the first gap
  314.                                 ParseVectorLine.DashGap(1) = _
  315.                                         .ParseUnit(igUnitDistance, _
  316.                                                 CStr(Abs(temparray(0))) & _
  317.                                                             gfrmPattern.cmbLength.Text)
  318.                                 PreviousNegative = True
  319.                                 dashgapcount = 2
  320.                             ElseIf temparray(0) = 0 Then 'zero
  321.                                 'Convert line thickness to use proper locale decimal delimiter.
  322.                                 If lReturnValue <> 0 Then
  323.                                     thickstring = ConvertDecimalDelimiter(Trim(gfrmPattern.cmbThick.Text), sDelimiter)
  324.                                 End If
  325.                                 
  326.                                 'Create a Dot Dash.  This should be equal to the thickness of a line
  327.                                 ParseVectorLine.DashGap(0) = _
  328.                                         .ParseUnit(igUnitDistance, _
  329.                                                     thickstring)
  330.                                 dashgapcount = 1
  331.                             Else 'Create a Dash
  332.                                 ParseVectorLine.DashGap(0) = _
  333.                                                 .ParseUnit(igUnitDistance, _
  334.                                                             CStr(Abs(temparray(0))) & " " & gfrmPattern.cmbLength.Text)
  335.                                 dashgapcount = 1
  336.                             End If
  337.                         Else
  338.                             'test to see if value for temparray is negative (indicating a gap)
  339.                             If temparray(j) < 0 Then
  340.                                 'test to see if previous value was negative
  341.                                 If PreviousNegative Then
  342.                                     ' add temparray value to the previous gap
  343.                                     ParseVectorLine.DashGap(dashgapcount - 1) = _
  344.                                         .ParseUnit(igUnitDistance, _
  345.                                                 CStr(Abs(temparray(j))) & _
  346.                                                             gfrmPattern.cmbLength.Text)
  347.                                 Else
  348.                                     'create a new gap
  349.                                     ParseVectorLine.DashGap(dashgapcount) = _
  350.                                                     .ParseUnit(igUnitDistance, _
  351.                                                             CStr(Abs(temparray(j))) & _
  352.                                                                 gfrmPattern.cmbLength.Text)
  353.                                     dashgapcount = dashgapcount + 1
  354.                                 End If
  355.                                 PreviousNegative = True
  356.                             ElseIf temparray(j) > 0 Then 'dash
  357.                                 'test to see if previous value was negative
  358.                                 If PreviousNegative Then
  359.                                     'create a new dash
  360.                                     ParseVectorLine.DashGap(dashgapcount) = _
  361.                                                     .ParseUnit(igUnitDistance, _
  362.                                                         CStr(Abs(temparray(j))) & _
  363.                                                             gfrmPattern.cmbLength.Text)
  364.                                     dashgapcount = dashgapcount + 1
  365.                                 Else
  366.                                     'add temparray value to the previous dash
  367.                                     ParseVectorLine.DashGap(dashgapcount - 1) = _
  368.                                                     .ParseUnit(igUnitDistance, _
  369.                                                         CStr(Abs(temparray(j))) & _
  370.                                                             gfrmPattern.cmbLength.Text)
  371.                                 End If
  372.                                 PreviousNegative = False
  373.                             Else
  374.                                 'test to see if previous value was negative
  375.                                 If PreviousNegative Then
  376.                                     'create a new dash dot
  377.                                     ParseVectorLine.DashGap(dashgapcount) = _
  378.                                         .ParseUnit(igUnitDistance, _
  379.                                                     gfrmPattern.cmbThick.Text)
  380.                                     dashgapcount = dashgapcount + 1
  381.                                 End If
  382.                                 PreviousNegative = False
  383.                             End If
  384.                         End If
  385.                     Next j
  386.                     'Test to see if there are an even number of dashes and gaps
  387.                     If (dashgapcount) Mod 2 > 0 Then
  388.                         'odd number therefore add a zero length gap to the end
  389.                         ParseVectorLine.DashGap(dashgapcount) = 0
  390.                         dashgapcount = dashgapcount + 1
  391.                     End If
  392.                     ParseVectorLine.DashCount = dashgapcount
  393.                 Else
  394.                     ParseVectorLine.DashCount = 0
  395.                 End If
  396.                
  397.             End If
  398.         Next i
  399.     End With
  400.    
  401. End Function
  402.  
  403. Sub TestParser(hatchitem As HatchData)
  404. 'This is designed to make sure we're passing good data to the HatchPatternStyles Object
  405.     Dim i As Integer
  406.     Dim j As Integer
  407.     Dim tempstring As String
  408.     Debug.Print hatchitem.HatchName & "," & hatchitem.HatchDescription & "," & hatchitem.NumPasses
  409.     For i = 0 To hatchitem.NumPasses - 1
  410.         tempstring = ""
  411.         For j = 0 To hatchitem.Pass(i).DashCount - 1
  412.             tempstring = tempstring & hatchitem.Pass(i).DashGap(j) & ","
  413.         Next j
  414.         Debug.Print hatchitem.Pass(i).dRotation & "," & _
  415.                     hatchitem.Pass(i).dXOrigin & "," & _
  416.                     hatchitem.Pass(i).dYOrigin & "," & _
  417.                     hatchitem.Pass(i).dSpacing & "," & _
  418.                     hatchitem.Pass(i).dShift & "," & _
  419.                     "\\" & tempstring
  420.     Next i
  421.  
  422. End Sub
  423. Sub AddPattern(hatchitem As HatchData)
  424. 'Adds a fill pattern to the Active Imagineer Book
  425.     Dim i As Integer
  426.     Dim j As Integer
  427.     Dim ObjHatchStyle As Object
  428.     Dim objFillStyle As Object
  429.     Dim LineIndex As Integer
  430.     Dim tempstring As String
  431.     Dim sDashTypeName As String
  432.     Dim lReturnValue As Long
  433.     Dim sDecimalDelimiter As String * 10
  434.     Dim sDelimiter As String
  435.     Dim lDelimiterBuffer As Long
  436.     Dim lLocaleID As Long
  437.     Dim numstring As String
  438.  
  439.     
  440.     sDashTypeName = ""
  441.     
  442.     'Find decimal delimiter for this OS
  443.     lLocaleID = GetUserDefaultLCID
  444.     lDelimiterBuffer = Len(sDecimalDelimiter)
  445.     lReturnValue = GetLocaleInfo(lLocaleID, LOCALE_SDECIMAL, sDecimalDelimiter, lDelimiterBuffer)
  446.     
  447.     If lReturnValue = 0 Then
  448.         MsgBox "Error has occured while retrieving locale information.  Unable to continue.", vbExclamation
  449.     Else
  450.         sDelimiter = Left(sDecimalDelimiter, lReturnValue - 1)
  451.     End If
  452.    
  453.     'Test to see if the file style exists and prompt appropriately
  454.     With gobjBook
  455.         For Each objFillStyle In .FillStyles
  456.             If LCase(objFillStyle.Name) = LCase(hatchitem.HatchName) Then
  457.                 If MsgBox("The " & hatchitem.HatchName & " pattern already exists in the Active Book.  Do you wish to Overwrite?", _
  458.                             vbYesNo, "AutoCAD Pattern Conversion") = vbYes Then
  459.                     'remove the hatch
  460.                     tempstring = objFillStyle.Name
  461.                     .FillStyles.Remove tempstring
  462.                     .HatchPatternStyles.Remove tempstring
  463.                     Exit For
  464.                 Else
  465.                     
  466.                     Exit Sub
  467.                 End If
  468.             End If
  469.         Next
  470.             
  471.         Set ObjHatchStyle = .HatchPatternStyles.Add(hatchitem.HatchName, "")
  472.         ObjHatchStyle.Units = 11 ' Means Paper which will be the default eventually
  473.         ' Create a fill style object that will have the hatch as its pattern name.
  474.         Set objFillStyle = .FillStyles.Add(hatchitem.HatchName, "")
  475.         objFillStyle.PatternName = ObjHatchStyle.Name
  476.         objFillStyle.Units = ObjHatchStyle.Units
  477.         objFillStyle.Color = -2 ' Transparent
  478.         objFillStyle.FillBackground = False
  479.     
  480.  
  481.         If lReturnValue <> 0 Then
  482.             numstring = ConvertDecimalDelimiter(gfrmPattern.cmbThick.Text, sDelimiter)
  483.         End If
  484.  
  485.         For i = 0 To hatchitem.NumPasses - 1
  486.             
  487.            LineIndex = ObjHatchStyle.AddHatch(hatchitem.Pass(i).dRotation, _
  488.                                     hatchitem.Pass(i).dXOrigin, _
  489.                                     hatchitem.Pass(i).dYOrigin, _
  490.                                     hatchitem.Pass(i).dSpacing, _
  491.                                     hatchitem.Pass(i).dShift, _
  492.                                     igBlackColor, _
  493.                                     .UnitsOfMeasure.ParseUnit(igUnitDistance, _
  494.                                                         numstring), _
  495.                                     sDashTypeName)
  496.             If hatchitem.Pass(i).DashCount > 0 Then
  497.                 ObjHatchStyle.SetDashGap LineIndex, hatchitem.Pass(i).DashCount, hatchitem.Pass(i).DashGap
  498.             End If
  499.         Next i
  500.     End With
  501. End Sub
  502.  
  503. Public Function ConvertDecimalDelimiter(sNumber As String, sDecimalDelimiter As String) As String
  504.     Dim sInteger As String
  505.     Dim sFractional As String
  506.     Dim nPosition As Integer
  507.     
  508.     nPosition = InStr(sNumber, ".")
  509.     If nPosition <> 0 Then
  510.         sInteger = Left(sNumber, nPosition - 1)
  511.         sFractional = Right(sNumber, Len(sNumber) - nPosition)
  512.         ConvertDecimalDelimiter = sInteger & sDecimalDelimiter & sFractional
  513.     Else
  514.         ConvertDecimalDelimiter = sNumber
  515.     End If
  516.     
  517.     
  518. End Function
  519.  
  520. Public Sub CheckIfValidLocale()
  521.     Dim lLocaleID As Long
  522.     Dim lDelimiterBuffer As Long
  523.     Dim lReturnValue As Long
  524.     Dim sDecimalDelimiter As String * 10
  525.     Dim sDelimiter As String
  526.     Dim dTempValue As Double
  527.     Dim sDistance As String
  528.     Dim sErrorMsg As String
  529.     
  530.     'Find decimal delimiter for this OS
  531.     lLocaleID = GetUserDefaultLCID
  532.     lDelimiterBuffer = Len(sDecimalDelimiter)
  533.     lReturnValue = GetLocaleInfo(lLocaleID, LOCALE_SDECIMAL, sDecimalDelimiter, lDelimiterBuffer)
  534.  
  535.     If lReturnValue <> 0 Then
  536.         sDelimiter = Left(sDecimalDelimiter, lReturnValue - 1)
  537.         sDistance = ConvertDecimalDelimiter("1.0", sDelimiter)
  538.         
  539.         Set mobjUnitsOfMeasure = gfrmPattern.igCommand1.Application.ActiveBook.UnitsOfMeasure
  540.  
  541.         On Error GoTo ErrorHandler
  542.         
  543.         'Make sure that we can parse distances
  544.         sErrorMsg = "Warning - For this sample to work properly the Length Units and Angle Units on the main form must be translated to match the current locale of this operating system."
  545.         dTempValue = mobjUnitsOfMeasure.ParseUnit(igUnitDistance, sDistance & " " & gfrmPattern.cmbLength.Text)
  546.         
  547.         'Make sure that we can parse angles
  548.         sErrorMsg = "Warning - For this sample to work properly the Angle Units on the main form must be translated to match the current locale of this operating system."
  549.         dTempValue = mobjUnitsOfMeasure.ParseUnit(igUnitAngle, "90 " & gfrmPattern.cmbAngle.Text)
  550.  
  551.         Set mobjUnitsOfMeasure = Nothing
  552.         On Error GoTo 0
  553.         Exit Sub
  554.     End If
  555.     
  556. ErrorHandler:
  557.     Set mobjUnitsOfMeasure = Nothing
  558.     MsgBox sErrorMsg, vbCritical
  559.     Exit Sub
  560.     
  561. End Sub
  562.