TheSwamp
Code Red => VB(A) => Topic started by: David Hall on August 08, 2007, 12:30:38 PM
-
What seems like such a simple question has led to some interesting error trapping. I keep getting a type mismatch with the following if the enter key is pressed w/o a valid entry
dim dblTOC as double
dblTOC = CDbl(InputBox("What is T.O.C. elevation? ie 12 or 0 or -12"))
What I was thinking was trying to use something like InitializeUserInput to prevent the esc or blank-enter key
Any ideas
-
I don't have any input; but I am wondering what is this little functions' function?
-
From the help file.
1 Disallows NULL input. This prevents the user from responding to the request by entering only [Return] or a space.
2 Disallows input of zero (0). This prevents the user from responding to the request by entering 0.
4 Disallows negative values. This prevents the user from responding to the request by entering a negative value.
8 Does not check drawing limits, even if the LIMCHECK system variable is on. This enables the user to enter a point outside the current drawing limits. This condition applies to the next user-input function even if the AutoCAD LIMCHECK system variable is currently set.
16 Not currently used.
32 Uses dashed lines when drawing rubber-band lines or boxes. This causes the rubber-band line or box that AutoCAD displays to be dashed instead of solid, for those methods that let the user specify a point by selecting a location on the graphics screen. (Some display drivers use a distinctive color instead of dashed lines.) If the POPUPS system variable is 0, AutoCAD ignores this bit.
64 Ignores Z coordinate of 3D points (GetDistance method only). This option ignores the Z coordinate of 3D points returned by the GetDistance method, so an application can ensure this function returns a 2D distance.
128 Allows arbitrary input—whatever the user types.
-
Matt, thanks, but aren't those bits for InitializeUserInput? I am trying to use an InputBox, and I cannot find any documentation on setting bits for its use.
MJF-The function of that box is part of a larger function to put in a block with elevation. I wrote a program to draw a Electricl Substation in 3d.
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Sub AddPT()
Const VK_ESCAPE = &H1B
Const VK_LBUTTON = &H1
Const VK_SPACE = &H20
Const VK_RETURN = &HD
Const VK_LEFT = &H25
Dim inspt As Variant
Dim intOSMode As Integer
Dim dblRotation As Double
Dim objBlockRef As AcadBlockReference, dblTOC As Double
Dim varCancel As Variant, oCurrLayeR As AcadLayer
On Error GoTo Err_Control
Set oCurrLayeR = ThisDrawing.ActiveLayer
IsSetup
Start:
dblTOC = CDbl(InputBox("What is T.O.C. elevation? ie 12 or 0 or -12"))
ThisDrawing.SetVariable "ORTHOMODE", 1
intOSMode = ThisDrawing.GetVariable("OSMODE")
ThisDrawing.SetVariable "OSMODE", 32
inspt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point: ")
inspt(2) = inspt(2) + dblTOC
ThisDrawing.SetVariable "OSMODE", intOSMode
dblRotation = ThisDrawing.Utility.GetAngle(inspt, "Pick Front Side of PT: ")
Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(inspt, Path & "138kv-PT-ASSEMBLY.dwg", 1, 1, 1, dblRotation)
ThisDrawing.Regen acActiveViewport
Exit_Here:
ThisDrawing.ActiveLayer = oCurrLayeR
ThisDrawing.SetVariable "OSMODE", intOSMode
ThisDrawing.SetVariable "INSUNITS", 1
Exit Sub
Err_Control:
Select Case Err.Number
Case -2147352567
'Debug.Print Err.Number, Err.Description
varCancel = ThisDrawing.GetVariable("LASTPROMPT")
If InStr(1, varCancel, "*Cancel*") <> 0 Then
If GetAsyncKeyState(VK_ESCAPE) And 8000 > 0 Then
Err.Clear
Resume Exit_Here
ElseIf GetAsyncKeyState(VK_LBUTTON) > 0 Then
Err.Clear
Resume
End If
Else
If GetAsyncKeyState(VK_SPACE) Then
Resume Exit_Here
End If
'Missed the pick, send them back!
Err.Clear
Resume
End If
Case 13
GoTo Start
Case Else
MsgBox Err.Description
Resume Exit_Here
End Select
End Sub
As you can see, its a basic function, but I never planned on my users NOT entering a value.
-
Doing a quick search I came across these... Maybe one will help??!?
http://www.dailydoseofexcel.com/archives/2005/05/04/1118/
http://www.dicks-blog.com/archives/2004/05/26/validating-an-inputbox/
http://www.vba-programmer.com/Snippets/Code_VB/InputBox_Cancel_vs_No_Input.html
-
The last one looks good, but I have a question, would I have to get rid of my on error statement to make that work?
-
I can't think of any reason you would need to keep it. If you press the cancel button or esc you get a message. If the inputbox is empty, you get a message. Looks like all the bases are covered. Unless I'm missing something??!?
-
Well, (I'm not trying to be a PITA) but if I take out the err control, what happens if user pushes ESC while selecting an insertion pt?
-
Nevermind ^ I can use InitializeUserInput to make them pick a point
-
Yeah... you'll definitely need some kind of error control for the point picking. I was just focusing on the inputbox - sorry.
-
ok, so this is getting harder by the minute. I got the Inputbox err control working, but now everything else breaks.
-
For now, I am going to Exit Sub if they hit ESC
-
A tough one as there aren't too many options.
This may be of some use
Sub MOX()
Dim dblTOC As Double
Dim sAns As String
Dim sTitle As String
sTitle = "What is T.O.C. elevation? ie 12 or 0 or -12"
Repeat:
sAns = InputBox(sTitle)
If sAns = "" Then
Exit Sub
End If
If Not IsNumeric(sAns) Then
sTitle = "Please type a number"
GoTo Repeat
End If
dblTOC = CDbl(sAns)
Debug.Print dblTOC
End Sub