dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: InputBox "resilience" for blank entries and selecting [OK] or [Cancel].

  1. #1
    Join Date
    Nov 2003
    Posts
    21

    InputBox "resilience" for blank entries and selecting [OK] or [Cancel].

    Hi There.

    Please see the following code:


    Code:
    Sub Choice()
    'Sub-Routine that handles initial input and choices from user.
    
    InitialInput = InputBox("The following program calculates the Surface Area, Volume and Relative Density of a variety of objects." & vbCrLf & _
                            "" & vbCrLf & _
                            "Please choose a shape from the following list by inputting its corresponding number and either pressing [Return] or clicking [OK]." & vbCrLf & _
                            "" & vbCrLf & _
                            "1: Sphere," & vbCrLf & _
                            "2: Cylinder," & vbCrLf & _
                            "3: Cuboid," & vbCrLf & _
                            "" & vbCrLf & _
                            "To exit the program please press 9.")
    If InitialInput = 1 Then
        Call Sphere
    ElseIf InitialInput = 2 Then
        Call Cylinder
    ElseIf InitialInput = 3 Then
        Call Cuboid
    ElseIf InitialInput = 9 Then
        End
    ElseIf InitialInput <> 1 Or 2 Or 3 Or 9 Then
        picDisplay.Print ("You have inputted an invalid choice, please retry")
        call Choice
    End If
    
    End Sub
    (Please ignore the rather poorly indented text for the
    inputbox at the top - copy
    and paste doesnt appear to take on-board tabbed
    information too well! Course, it could just be me!)

    As you will see by:

    Code:
    ElseIf InitialInput <> 1 Or 2 Or 3 Or 9 Then
        picDisplay.Print ("You have inputted an invalid choice, please retry")
    and

    Code:
    Call Choice
    I have built in some resilience to the program by making it ouput
    an error to the picDiplay and call the Choice subroutine if
    someone doesn't enter 1, 2, 3 or 9 in the inputbox.

    Is it possible to incorporate something within the code to "know"
    if someone has left the inputbox blank and just clicked [OK] or
    [Cancel] so that I could be crafty and output another error to the
    picDiplay and again call the Choice routine.

    (P.S. Sorry that this is v.v.v simple stuff - just started a college
    course! Guess everyone has to start somewhere!!!)

    Many thanks for looking! Cheers.
    Last edited by Cimperiali; November 11th, 2003 at 04:51 PM.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    A great MKsa know how...

    Have a look:
    http://www.codeguru.com/forum/showth...767#post553767
    here Mksa shows us how to know, when returned val from inputbox is vbnull, if user pressed Ok or pressed Cancel
    Last edited by Cimperiali; November 12th, 2003 at 03:01 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651
    Code:
    If Len(Trim(InitialInput)) = 0 then
         'Error Message Goes Here
    End if
    I'd rather be wakeboarding...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)