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.
:wave:
Thanks in advance.
Wulfgur
Re: Quick Question - inputboxes
If i understood you correctly then you ment something like this:
VB Code:
Dim NeededText As String
Do Until NeededText="test"
NeededText=InputBox("Enter test Here!")
Loop
MessageBox.Show("String test Recieved!")
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:
Dim NeededText As String
Do
NeededText=InputBox("Enter test Here!")
Loop Until NeededText="test"
MessageBox.Show("String test Recieved!")
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.
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
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.
Re: Quick Question - inputboxes
Could you give me an example on how to do it please.
Thanks
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.
Re: Quick Question - inputboxes
Ok thanks that made it more clear.
Thanks again for the help all.