error checking value

Discussion in 'AutoCAD' started by Lunt, Jul 22, 2004.

  1. Lunt

    Lunt Guest

    here is a part of the code:

    ThisDrawing.Utility.InitializeUserInput 132, UserKeyWord
    DistText = ThisDrawing.Utility.GetReal("Please enter the distance between stations or hit 'S' to (Select): ")
    varInput = ThisDrawing.Utility.GetInput

    If Err Then
    If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
    Err.Clear
    ThisDrawing.Utility.GetEntity DistanceText2, ptPicked, "Please select the DISTANCE to the last deflection point:"
    dblHoldingDistance = CDbl(DistanceText2.TextString)
    ETC. ETC. ETC.

    my question is this: the user can either enter a distance (i.e. 232.54) or type "S" to physically select the distance text....My UserKeyWord is "S" (Select)....no matter what I enter into the command prompt (i.e "a", or "wefdrt" , any garbage text)...it tells me the err.description is "User input is a keyword"....but it should not be, ONLY "S" should be the keyword...any suggestions?
    HELP PLS......my error checking is horrid and this is the only thing left for me to code properly....arggghhh
     
    Lunt, Jul 22, 2004
    #1
  2. Hi,

    You difficulty is that you are asking for a Real with "Getreal". Anything
    else will generate an error.

    You would be better off to get a string.
    Check the value of the string - ie

    if val(string) > 0 then
    You have a value - does as you like with it
    elseif string = "S" then
    You have an S - do as you like with it
    else
    Msgbox " You monumental twit!!!! Read my instructions" ' :-}
    end if

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    stations or hit 'S' to (Select): ")
    DISTANCE to the last deflection point:"
    type "S" to physically select the distance text....My UserKeyWord is "S"
    (Select)....no matter what I enter into the command prompt (i.e "a", or
    "wefdrt" , any garbage text)...it tells me the err.description is "User
    input is a keyword"....but it should not be, ONLY "S" should be the
    keyword...any suggestions?
    for me to code properly....arggghhh
     
    Laurie Comerford, Jul 23, 2004
    #2
  3. Lunt

    Jürg Menzi Guest

    Hi Lunt

    This sample shows you how to do:

    ' - Begin code
    Public Function GetRealTest() As Variant

    Dim RetVal As Variant

    On Error Resume Next

    With ThisDrawing.Utility
    .InitializeUserInput 6, "Select"
    RetVal = .GetReal("Please enter distance between stations or [Select]: ")
    If Err Then
    If Err.Number = -2145320928 Then
    Err.Clear
    GetRealTest = .GetInput
    Else
    Err.Clear
    GetRealTest = vbEmpty
    End If
    Else
    GetRealTest = RetVal
    End If
    End With

    End Function
    ' - End code

    Returns:
    - "Select" in case of keyboard input 'S' or 'Select' on right click context
    menu
    - The entered Double
    - vbEmpty if the user is hitting 'Enter' or another error occur

    Cheers
     
    Jürg Menzi, Jul 23, 2004
    #3
  4. Lunt

    Lunt Guest

    thank you both for your suggestions...i figured it out last night...greatly appreciated :)
     
    Lunt, Jul 23, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.