Results 1 to 9 of 9

Thread: Quick Question - inputboxes

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Quick Question - inputboxes

    Hello,

    I started Learning Visual Basic.net (Visual Studio 2005) a few days ago and have just been trying new things out and seeing how everything works, i've checked out MSDN online for some basic help when needed.

    I was wondering if somone would be able to post a script of:
    Click a button so an inputbox comes up. (i got that done easily)
    Then have it say eg. enter the word "test" (got that done)
    but i got stuck with the loop: if "test" isn't entered try again.
    and inputbox comes back up asking to eneter "test"

    Hope that makes sense.

    One more thing, could somone post a messagebox loop if its not to much trouble.


    Thanks in advance.



    Wulfgur

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Quick Question - inputboxes

    If i understood you correctly then you ment something like this:

    VB Code:
    1. Dim NeededText As String
    2.  
    3. Do Until NeededText="test"
    4. NeededText=InputBox("Enter test Here!")
    5. Loop
    6. MessageBox.Show("String test Recieved!")

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Quick Question - inputboxes

    That code will certainly do the desired job but there's no point testing the string before the InputBox has been displayed the first time so a post-test would be more appropriate than a pre-test:
    VB Code:
    1. Dim NeededText As String
    2.  
    3. Do
    4.     NeededText=InputBox("Enter test Here!")
    5. Loop Until NeededText="test"
    6.  
    7. MessageBox.Show("String test Recieved!")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Quick Question - inputboxes

    Also, you will probably recognize quite quickly that the InputBox, while it appears to be of some value, is NEVER the right way to do things. The box is terribly limitted, as you have already found. Is there ANY other dialog box that you are virtually forced to show in a loop to get it right? The purpose for a dialog box is to provide information (no return), or to get user input (some return). You show the box...then you deal with the result. Normally, you do your validation in the dialog itself. In the case of the InputBox, you show the dialog, then, if the user doesn't do the right thing, you get to show it again...and again....and again.

    Do you want to tell the user what's wrong? Ok, show them a messagebox, then show them the InputBox again!!! This is NEVER a good idea. Far better would be to make a simple form that has a textbox, a label (if you want), and one or two option buttons. Any validation of the data entered can be performed while still in that form, and only once the data is in a known good state does the dialog box close.

    This is better encapsulation of the data acquisition than the InputBox can ever be, and would remove the need for you to even ask this question. It's good to know about InputBox, but I would strongly suggest that you think twice before ever actually using it.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: Quick Question - inputboxes

    Thanks for the quick replies and help.

    Shaggy Hiker, i sort of understand what you are saying but not 100%, would you be able to post a script of it if possible or a screenshot. Thanks

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Quick Question - inputboxes

    What Shaggy suggested is to create your own custom inputbox, and he's right... It's quite simple to do, and it gives you total control over what you want it to do.

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: Quick Question - inputboxes

    Could you give me an example on how to do it please.

    Thanks

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Quick Question - inputboxes

    Well, you've created a form by now, so you know that part. The InputBox function simply shows a form that has a label, a textbox, and two buttons: OK and CANCEL.

    If you were to make a form that has just these controls on it, then you would have the same functionality that the InputBox function has. However, you would be able to check the contents of the textbox in the button click event of the OK button.

    I wasn't intending anything more than that, but you could expand on that by adding a property to allow the setting of the text in the label, the caption of the form, and the contents of the textbox, but none of that is really necessary.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: Quick Question - inputboxes

    Ok thanks that made it more clear.

    Thanks again for the help all.

Posting Permissions

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



Click Here to Expand Forum to Full Width