Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incompatible type?(API problem)

Status
Not open for further replies.

Cessar

Mechanical
May 9, 2007
7
0
0
FR
Hi,
I have got macro in VBA for SW which takes selected point,puts on this point new coordinte system and later should use this coordinates to another part of program.But it still sees some problem about incompatible type of variable.
below i putted my code:
***After clicking the button:
Private Sub cmd1_Click()
Blo.Hide
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swSelData As SldWorks.SelectData
Dim bRet As Boolean
Dim swFace As SldWorks.Face2
Dim swPoint As SldWorks.Vertex
Dim vPoint As Variant
Dim swSkCofG As SldWorks.SketchPoint
Dim seltype As Long
Dim FormatedX As Single
Dim FormatedY As Single
Dim FormatedZ As Single

Const MINSELECTIONS = 1

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swSelData = swSelMgr.CreateSelectData

Do
swModel.ClearSelection2 True 'clear selections
MsgBox " Select VERTEX where You want to place Coordinate system. ", vbOKOnly Or vbInformation

While swSelMgr.GetSelectedObjectCount < MINSELECTIONS
DoEvents 'Wait for user selection
Wend

seltype = swSelMgr.GetSelectedObjectType2(1)
Loop While (seltype <> SwConst.swSelectType_e.swSelVERTICES)

Set swPoint = swSelMgr.GetSelectedObject5(1)
vPoint = swPoint.GetPoint

swModel.Insert3DSketch2 False
swModel.SetAddToDB True

Set swSkCofG = swModel.CreatePoint2(vPoint(0), vPoint(1), vPoint(2))

swModel.Insert3DSketch2 False
swModel.ClearSelection2 True

'Definition of the Relative X,Y,Z
FormatedX = Format(vPoint(0) * 1000, "#####0.0000")
FormatedY = Format(vPoint(1) * 1000, "#####0.0000")
FormatedZ = Format(vPoint(2) * 1000, "#####0.0000")

GivingInformation.setRelativeX (FormatedX)
GivingInformation.setRelativeY (FormatedY)
GivingInformation.setRelativeZ (FormatedZ)

swSelData.Mark = 1
bRet = swSkCofG.Select4(True, swSelData)

bRet = swModel.InsertCoordinateSystem(False, False, False)
MsgBox " The Coordinate system has been definied at the selected place. ", vbOKOnly Or vbInformation

swModel.ClearSelection2 True 'clear selections

CleanUp:
Set swFace = Nothing
Set swSurf = Nothing
Set swSelMgr = Nothing
Set swModel = Nothing
Set swApp = Nothing
Blo.Show
Call Info
End Sub

***In GivingInformation module there is:
Dim RelativeX As Single
Dim RelativeY As Single
Dim RelativeZ As Single

Public Sub setRelativeX(variable As Single)
RelativeX = variable
End Sub

Public Sub setRelativeY(variable As Single)
RelativeY = variable
End Sub

Public Sub setRelativeZ(variable As Single)
RelativeZ = variable
End Sub
Function Info()
If RelativeX = 0 & RelativeY = 0 & RelativeZ = 0 Then '***HERE IS THE PROBLEM
MsgBox "Something"
Else
MsgBox " X = " & RelativeX & vbCrLf & " Y = " & RelativeY & vbCrLf & " Z = " & RelativeZ
End If
End Function

Every time on line "If RelativeX=0 & Relat..." there message that type is incompatible.I have no idea how I should solve it.If anybody could help me i will be grateful.
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top