Input Methods and Dialogs

All the AutoCAD input methods require that the user interact with the AutoCAD drawing or command window. To use these methods from a VBA UserForm, either hide the form before you call the input methods or set the UserForm to modeless operation. If you don't, an error will occur. This is because modal forms maintain the application focus while they're visible. As long as a modal VBA form is visible, there's no way for the user to get to the AutoCAD drawing or command window. UserForms can be modal or modeless only with AutoCAD 2002 and later versions.

The following example places the command button cmdGetReal on a UserForm, which is then hidden while the GetReal user input method executes:

Private Sub cmdGetReal_Click() Dim dblInput As Double

Me.Hide dblInput = ThisDrawing.Utility.GetReal("Enter a real value: ") Me.Show

End Sub

■ Note Remember to Show the form after you Hide it for the GetReal user input method, or your program will exit without completing any of the form's remaining code.

The code in this chapter runs from the Macros dialog box. To work from a UserForm, you need to modify each sample. For example, change code from this:

Public Sub TestUserInput() Dim strInput As String

With ThisDrawing.Utility

.InitializeUserInput 1, "Line Arc Circle laSt"

strInput = .GetKeyword(vbCr & "Option [Line/Arc/Circle/laSt]: ")

.Prompt "You selected '" & strInput & "'"

End With End Sub to this:

Private Sub CommandButton1_Click() Dim strInput As String

Me.Hide

With ThisDrawing.Utility

.InitializeUserInput 1, "Line Arc Circle laSt"

strInput = .GetKeyword(vbCr & "Option [Line/Arc/Circle/laSt]: ")

MsgBox "You selected '" & strInput & "'"

End With

Me.Show

End Sub

Programs written using the full version ofVisual Basic 6 or VBA 6.3 (AutoCAD 2002 and later) are not limited to modal dialog forms. But sometimes it may make sense to hide the form while interacting with the user at the AutoCAD command prompt. Try to think like your users when you design the interaction process and your forms' behavior.

0 0

Post a comment