iCAx开思工具箱

标题: 请大家帮忙修改下程序里的错误,急! [打印本页]

作者: sherry1860    时间: 2006-6-26 21:18
标题: 请大家帮忙修改下程序里的错误,急!
小第在做二次开发中的程序中遇到如下错误,运行时,总是弹出“变量未定义”这个窗口,由于对VB不熟悉,因此急得抓耳挠腮,请高手帮忙看下,出错时显示的要调整的句子为红色部分。此为VB程序



Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()

If Dir(App.Path & "\公差零件.SLDDRW") = "" Then
    Call MsgBox("此文件不存在!", vbExclamation)
    Exit Sub
End If
'使用默认程序打开文件
Call ShellExecute(hwnd, "Open", App.Path & "\公差零件.SLDDRW", "", App.Path, 1)

End Sub

Private Sub Command2_Click()


Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.ActivateView("工程视图4")
boolstatus = Part.Extension.SelectByID2("RD5@工程视图4", "DIMENSION", 1.064601075149, 0.6697319222769, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("图纸1", "SHEET", 1.067232377125, 0.6657849693126, 0, False, 0, Nothing, 0)

Dim DatumTag As Object
Dim Annotation As Object

Set DatumTag = Part.InsertDatumTag2()
If Not DatumTag Is Nothing Then
   DatumTag.FilledTriangle = 1
   DatumTag.Shoulder = 0
   Set Annotation = DatumTag.GetAnnotation()
   If Not Annotation Is Nothing Then
      boolstatus = Annotation.SetPosition(1.067232377125, 0.6552597614075, -3.550623543045E-15)
   End If
End If

Part.WindowRedraw
boolstatus = Part.Extension.SelectByID2("RD5@工程视图4", "DIMENSION", 1.065916726137, 0.7868248602204, 0, False, 0, Nothing, 0)

Dim Gtol As Object

Set Gtol = Part.InsertGtol()
If Not Gtol Is Nothing Then
   Gtol.SetFrameSymbols2 1, "<IGTOL-CONC>", 1, "", 0, "", "", "", ""
   Gtol.SetFrameValues 1, "0.03", "", "A", "", ""
   Gtol.SetFrameSymbols2 2, "", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 2, "", "", "", "", ""
   Gtol.SetPTZHeight "", 0
   Gtol.SetCompositeFrame 0
   Gtol.SetBetweenTwoPoints 0, "", ""
   Set Annotation = Gtol.GetAnnotation()
   If Not Annotation Is Nothing Then
      boolstatus = Annotation.SetPosition(1.052105684718, 0.7261915134276, 0)
      longstatus = Annotation.SetLeader2(0, 0, 1, 1, 0, 0)
   End If
End If

Part.WindowRedraw
boolstatus = Part.Extension.SelectByID2("RD8@工程视图4", "DIMENSION", 0.3673060514411, 0.7605118404578, 0, False, 0, Nothing, 0)


Set Gtol = Part.InsertGtol()
If Not Gtol Is Nothing Then
   Gtol.SetFrameSymbols2 1, "<IGTOL-CONC>", 1, "", 0, "", "", "", ""
   Gtol.SetFrameValues 1, "0.008", "", "A", "", ""
   Gtol.SetFrameSymbols2 2, "", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 2, "", "", "", "", ""
   Gtol.SetPTZHeight "", 0
   Gtol.SetCompositeFrame 0
   Gtol.SetBetweenTwoPoints 0, "", ""
   Set Annotation = Gtol.GetAnnotation()
   If Not Annotation Is Nothing Then
      boolstatus = Annotation.SetPosition(0.3418670761091, 0.7300920523966, 0)
      longstatus = Annotation.SetLeader2(0, 0, 1, 1, 0, 0)
   End If
End If

Part.WindowRedraw
boolstatus = Part.ActivateView("工程视图2")
boolstatus = Part.Extension.SelectByID2("RD1@工程视图2", "DIMENSION", 0.130488873578, 0.6513128084431, 0, False, 0, Nothing, 0)


Set Gtol = Part.InsertGtol()
If Not Gtol Is Nothing Then
   Gtol.SetFrameSymbols2 1, "<IGTOL-SYMMETRY>", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 1, "0.02", "", "A", "", ""
   Gtol.SetFrameSymbols2 2, "", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 2, "", "", "", "", ""
   Gtol.SetPTZHeight "", 0
   Gtol.SetCompositeFrame 0
   Gtol.SetBetweenTwoPoints 0, "", ""
   Set Annotation = Gtol.GetAnnotation()
   If Not Annotation Is Nothing Then
      boolstatus = Annotation.SetPosition(0.1078748499866, 0.644280195078, 0)
      longstatus = Annotation.SetLeader2(0, 0, 1, 1, 0, 0)
   End If
End If

Part.WindowRedraw
boolstatus = Part.ActivateView("工程视图4")
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.8593595210011, 0.6671006203024, 249.96, False, 0, Nothing, 0)


Set Gtol = Part.InsertGtol()
If Not Gtol Is Nothing Then
   Gtol.SetFrameSymbols2 1, "<IGTOL-CYL>", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 1, "0.005", "", "", "", ""
   Gtol.SetFrameSymbols2 2, "", 0, "", 0, "", "", "", ""
   Gtol.SetFrameValues 2, "", "", "", "", ""
   Gtol.SetPTZHeight "", 0
   Gtol.SetCompositeFrame 0
   Gtol.SetBetweenTwoPoints 0, "", ""
   Set Annotation = Gtol.GetAnnotation()
   If Not Annotation Is Nothing Then
      boolstatus = Annotation.SetPosition(0.8657095210011, 0.6380144473886, 0.03)
      longstatus = Annotation.SetLeader2(1, 0, 1, 1, 0, 0)
   End If
End If

Part.WindowRedraw
boolstatus = Part.ActivateView("工程视图2")
Dim SFSymbol As Object
Set SFSymbol = Part.Extension.InsertSurfaceFinishSymbol3(1, 0, 0.1376677562039, 0.6445320878061, 0, 0, 1, "", "", "", "", "", "3.2", "")
boolstatus = Part.ActivateView("工程视图4")
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.429134917448, 0.7015137128612, 249.96, False, 0, Nothing, 0)
Set SFSymbol = Part.Extension.InsertSurfaceFinishSymbol3(1, 0, 0.42913812772, 0.7014153921985, 0.03, 0, 1, "", "", "", "", "", "0.8", "")
boolstatus = Part.Extension.SelectByID2("工程视图4", "DRAWINGVIEW", 0.633694851992, 0.7921103972968, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.6263159365175, 0.7900606985556, 249.96, False, 0, Nothing, 0)
Set SFSymbol = Part.Extension.InsertSurfaceFinishSymbol3(1, 0, 0.6263159365175, 0.7905144473886, 0.03, 0, 1, "", "", "", "", "", "0.4", "")
boolstatus = Part.Extension.SelectByID2("", "EDGE", 0.95590749438, 0.697824255124, 249.96, False, 0, Nothing, 0)
Set SFSymbol = Part.Extension.InsertSurfaceFinishSymbol3(1, 0, 0.95590749438, 0.6985144473886, 0.03, 0, 1, "", "", "", "", "", "1.6", "")
boolstatus = Part.ActivateSheet("图纸1")
boolstatus = Part.Extension.SelectByID2("图纸1", "SHEET", 0.2956175413338, 0.8144111196199, 0, False, 0, Nothing, 0)
Set SFSymbol = Part.Extension.InsertSurfaceFinishSymbol3(1, 0, 0.2956175413338, 0.8144111196199, 0, 0, 1, "", "", "", "", "", "12.5", "")
Part.FontFace "仿宋_GB2312"
boolstatus = Part.ActivateView("工程视图2")
Part.FontPoints 20

Dim Note As Object
Dim TextFormat As Object
Set Note = Part.InsertNote("<FONT name=""仿宋_GB2312"" size=20PTS><FONT color=D><FONT name=""Century Gothic"" size=3.5 style=RB effect=RU><FONT style=RI effect=RS>其余")
If Not Note Is Nothing Then
   Note.Angle = 0
   boolstatus = Note.SetBalloon(0, 0)
   Set Annotation = Note.GetAnnotation()
   If Not Annotation Is Nothing Then
      longstatus = Annotation.SetLeader2(False, 0, True, False, False, False)
      boolstatus = Annotation.SetPosition(0.2690534456254, 0.8237577458876, 0)

      Set TextFormat = Part.GetUserPreferenceTextFormat(swDetailingNoteTextFormat)
      TextFormat.Italic = False
      TextFormat.Underline = False
      TextFormat.Strikeout = False
      TextFormat.Bold = False
      TextFormat.Escapement = 0
      TextFormat.LineSpacing = 0.001
      TextFormat.CharHeight = 0.0035
      TextFormat.TypeFaceName = "Century Gothic"
      TextFormat.WidthFactor = 1
      TextFormat.ObliqueAngle = 0
      TextFormat.LineLength = 0
      TextFormat.Vertical = False
      TextFormat.BackWards = False
      TextFormat.UpsideDown = False
      TextFormat.CharSpacingFactor = 1
      boolstatus = Annotation.SetTextFormat(0, False, TextFormat)
   End If
End If
Part.ClearSelection2 True
Part.WindowRedraw
End Sub


作者: blackriver    时间: 2006-6-27 17:43
红色改为以下两句试试:
dim swApp as Application.SldWorks
Set swApp = new Application.SldWorks
作者: sherry1860    时间: 2006-6-28 09:38
好象还是不行,试了下,问题改变了,现在是说:用户定义类型未定义,能否再帮我看下啊,谢谢~




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3