Author Topic: Best way to dis-allow null or esc or enterkey  (Read 2010 times)

0 Members and 1 Guest are viewing this topic.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Best way to dis-allow null or esc or enterkey
« 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

Code: [Select]
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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: Best way to dis-allow null or esc or enterkey
« Reply #1 on: August 08, 2007, 12:39:53 PM »
I don't have any input; but I am wondering what is this little functions' function?
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Guest

  • Guest
Re: Best way to dis-allow null or esc or enterkey
« Reply #2 on: August 08, 2007, 01:53:06 PM »
From the help file.

Quote
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.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #3 on: August 08, 2007, 03:25:11 PM »
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.

Code: [Select]
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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second


CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #5 on: August 08, 2007, 03:48:55 PM »
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?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Guest

  • Guest
Re: Best way to dis-allow null or esc or enterkey
« Reply #6 on: August 08, 2007, 03:53:24 PM »
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??!?

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #7 on: August 08, 2007, 04:10:38 PM »
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?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #8 on: August 08, 2007, 04:11:36 PM »
Nevermind ^ I can use InitializeUserInput to make them pick a point
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Guest

  • Guest
Re: Best way to dis-allow null or esc or enterkey
« Reply #9 on: August 08, 2007, 04:20:56 PM »
Yeah... you'll definitely need some kind of error control for the point picking.  I was just focusing on the inputbox - sorry.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #10 on: August 08, 2007, 04:24:09 PM »
ok, so this is getting harder by the minute.  I got the Inputbox err control working, but now everything else breaks.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Best way to dis-allow null or esc or enterkey
« Reply #11 on: August 08, 2007, 04:24:31 PM »
For now, I am going to Exit Sub if they hit ESC
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Bryco

  • Water Moccasin
  • Posts: 1849
Re: Best way to dis-allow null or esc or enterkey
« Reply #12 on: August 08, 2007, 05:58:04 PM »
A tough one as there aren't too many options.
This may be of some use
Code: [Select]
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