|
-
Feb 16th, 2010, 07:28 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Loop until the user inputs a valid answer?
Hi guys. Is it possible for you to loop a block of code until the user provides a valid input? Like, when I click the save button, the program will prompt the user for an integer value, and I would like to validate if the user has inputted a valid value. If the user fails to input a valid value, then the program will re-prompt the same message again until the user inputs a valid value. Eg:
Code:
If MsgBox("Add copies to this book?", MsgBoxStyle.YesNo, "Adding Book Copies") = MsgBoxResult.Yes Then
Dim CopyQty As String = InputBox("Amount of copies to generate:", "Add Book Copy")
If IsNumeric(CopyQty) = False or (CopyQty < 1) Then
MsgBox("Please key in a valid amount of copies to generate.", MsgBoxStyle.Information, "Invalid Input")
'Show input box again
End If
end if
Last edited by riechan; Feb 16th, 2010 at 07:42 AM.
====================
ほんとにどもありがとう!
Rie Ishida
-
Feb 16th, 2010, 07:52 AM
#2
Re: Loop until the user inputs a valid answer?
Use my Numeric Texbox:

http://www.vbforums.com/showthread.php?t=601413
Or use custom form:

I've attached a demo project with this form: (see attached file).
Last edited by cicatrix; Mar 16th, 2010 at 06:17 AM.
-
Feb 16th, 2010, 07:54 AM
#3
New Member
Re: Loop until the user inputs a valid answer?
Dim CopyQty As String
If MsgBox("Add copies to this book?", vbYesNo, "Adding Book Copies") = vbYes Then
CopyQty = ""
Do While Val(CopyQty) < 1
CopyQty = InputBox("Amount of copies to generate:", "Add Book Copy")
If IsNumeric(CopyQty) = False Or (Val(CopyQty) < 1) Then
CopyQty = MsgBox("Please key in a valid amount of copies to generate.", vbInformation, "Invalid Input")
CopyQty = "" 'Show input box again
End If
Loop
End If
i try this only in Vb6
-
Feb 16th, 2010, 08:38 AM
#4
Re: Loop until the user inputs a valid answer?
Use a While loop...
While answer <> 3
End While
-
Feb 16th, 2010, 08:51 AM
#5
Re: Loop until the user inputs a valid answer?
 Originally Posted by Jenner
Use a While loop...
While answer <> 3
End While
Turn Option Strict On and it will fail.
-
Feb 16th, 2010, 09:00 AM
#6
Re: Loop until the user inputs a valid answer?
 Originally Posted by cicatrix
Turn Option Strict On and it will fail.
Why? It's pseudocode. I'm not even declaring what type of variable "answer" is, though from checking if it's 3, you'd assume it's an integer.
-
Feb 16th, 2010, 09:04 AM
#7
Re: Loop until the user inputs a valid answer?
Inputbox returns a String. Well, never mind. This remark was not for you but for the OP.
-
Feb 19th, 2010, 10:56 AM
#8
Thread Starter
Addicted Member
Re: Loop until the user inputs a valid answer?
Thanks for the help guys. Here's what I did, using jumer's code as reference:
Code:
Dim CopyQty As String
CopyQty = ""
Do While Val(CopyQty) < 1
CopyQty = InputBox("Amount of copies to generate:", "Add Book Copy")
If IsNumeric(CopyQty) = False Or (Val(CopyQty) < 1) Then
MsgBox("Please key in a valid amount of copies to generate.", vbInformation, "Invalid Input")
CopyQty = ""
End If
Loop
====================
ほんとにどもありがとう!
Rie Ishida
-
Feb 19th, 2010, 11:11 AM
#9
Re: [RESOLVED] Loop until the user inputs a valid answer?
-
Feb 19th, 2010, 11:23 AM
#10
Re: [RESOLVED] Loop until the user inputs a valid answer?
 Originally Posted by dbasnett
I can't... Get account blocked message.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Feb 19th, 2010, 11:44 AM
#11
Re: [RESOLVED] Loop until the user inputs a valid answer?
I thought it's only me. Was already composing the message to admins
-
Feb 19th, 2010, 12:14 PM
#12
Re: [RESOLVED] Loop until the user inputs a valid answer?
Hack messaged me saying that "they" are working on it. "They" are the folks at internet.com
stanav's avatar seems to about sum it up.
-
Feb 19th, 2010, 03:20 PM
#13
Re: [RESOLVED] Loop until the user inputs a valid answer?
lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|