[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
Re: Loop until the user inputs a valid answer?
Use my Numeric Texbox:
http://www.vbforums.com/
http://www.vbforums.com/showthread.php?t=601413
Or use custom form:
http://i49.tinypic.com/xldov9.jpg
I've attached a demo project with this form: (see attached file).
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
Re: Loop until the user inputs a valid answer?
Use a While loop...
While answer <> 3
End While
Re: Loop until the user inputs a valid answer?
Quote:
Originally Posted by
Jenner
Use a While loop...
While answer <> 3
End While
Turn Option Strict On and it will fail.
Re: Loop until the user inputs a valid answer?
Quote:
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. :)
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.
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
Re: [RESOLVED] Loop until the user inputs a valid answer?
Re: [RESOLVED] Loop until the user inputs a valid answer?
Quote:
Originally Posted by
dbasnett
I can't... Get account blocked message.
Re: [RESOLVED] Loop until the user inputs a valid answer?
I thought it's only me. Was already composing the message to admins
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.
Re: [RESOLVED] Loop until the user inputs a valid answer?