SolidWorks机械工程师网——最大的SolidWorks学习平台

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

作者: yimingli    时间: 2006-6-26 21:10
标题: 请大家帮忙修改下错误,急!
小第在做二次开发中遇到了如下问题,在运行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, "", 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, "", 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, "", 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, "", 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
作者: 贵宝地    时间: 2006-6-26 21:10
Set swApp = Application.SldWorks————VBA的默认语法
如果是VB的话,就要这样————Set swApp = CreateObject(&quot;SldWorks.Application&quot;)
作者: 54terry    时间: 2006-6-26 21:18
楼主急到哪里去了啊啊?!!能得到闷神的指点还不赶快出来表示表示!
作者: jimmyjimmy    时间: 2006-6-26 21:26
得到帮助应该说声谢谢。
作者: 南飘中    时间: 2006-6-26 21:30
M版看版真早啊
作者: 大忱忱    时间: 2006-6-26 21:33
抱歉啊~最近急的不行,一直在跑着问老师,问不出结果,博士后啊~郁闷~
感谢闷神啊~已经可以了,谢谢~
作者: qiuhonghui    时间: 2006-6-26 21:37
网上高人还是多,非常感谢,我一定把论坛多介绍几个同学~




欢迎光临 SolidWorks机械工程师网——最大的SolidWorks学习平台 (https://www.swbbsc.com/) Powered by Discuz! X3.2