×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Incompatible type?(API problem)

Incompatible type?(API problem)

Incompatible type?(API problem)

(OP)
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.

RE: Incompatible type?(API problem)

You need to use the word "And", not "&".  "&" is only used for concatenating strings.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Incompatible type?(API problem)

(OP)
It works!
Simply thing,but very important.
Many thanks for your advice TheTick!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources