sccat 发表于 2004-11-15 17:31:00

[求助]vba怎么不按语句顺序执行?

以下程序直接执行不可以,但如果在vbarun对话框选逐语句就可以运行.
开始时我想在对话框按下一个按纽,然后在图上选一个点,插入一个块,就用了sample的程序试了一下,结果对话框是焦点的情况下不能用utility的getpoint,只能在form1.hide之后才能utility.getpoint.后来发现,ThisDrawing.SendCommand 以后对话框还在,但不是焦点,可以用utility.getpoint,所以我想在getpoint前用一个空的指令,让对话框仍然显示在屏幕上,但不是焦点.
Private Sub CommandButton2_Click()
                               
                       Dim returnPnt As Variant
                               
                       ThisDrawing.SendCommand ("_open")
                       
                       returnPnt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")
                       
                       
                       MsgBox "The WCS of the point is: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2) & vbCrLf & _
                                                                                       "(Enter the next value without prompting.)", , "GetPoint Example"
                               
                       returnPnt = ThisDrawing.Utility.GetPoint
                       MsgBox "The WCS of the point is: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2), , "GetPoint Example"
                               
                       Dim basePnt(0 To 2) As Double
                       basePnt(0) = 2#: basePnt(1) = 2#: basePnt(2) = 0#
                       returnPnt = ThisDrawing.Utility.GetPoint(basePnt, "Enter a point: ")
                       MsgBox "The WCS of the point is: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2)
                               
                       Dim lineObj As AcadLine
                       Set lineObj = ThisDrawing.ModelSpace.AddLine(basePnt, returnPnt)
                       ZoomAll
                       UserForm1.Show
                       
End Sub**** Hidden Message *****

mikewolf2k 发表于 2004-11-15 19:03:00

哈哈,我也碰到过这个问题,也是插入块,一步步执行没问题,连续执行就出问题。没办法解决,后全部改为sendcommand.

雪山飞狐_lzh 发表于 2004-11-15 20:40:00

ThisDrawing.SendCommand ("_open")
?
什么意思

sccat 发表于 2004-11-16 08:51:00

ThisDrawing.SendCommand ("_open")
主要是为了让焦点回到autocad,可以传入一个空的指令.
不过我发现sendcommand好象一般到最后才执行,不知道为什么?

雪山飞狐_lzh 发表于 2004-11-16 09:33:00

让焦点回到autocad,用AppActivate Application.Caption
页: [1]
查看完整版本: [求助]vba怎么不按语句顺序执行?