Results 1 to 7 of 7

Thread: [RESOLVED] Repeating msgbox...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Resolved [RESOLVED] Repeating msgbox...

    Hello everybody,

    I have a question (vb 2005).
    I have an inputbox that askes the user a question.

    If the user types in the right anwser a label appears with the text "good job!".
    If the user anwsers the wrong anwser than a label appears with the text "Wrong!".

    Here comes my problem.
    If the user types in nothing ("") I want a msgbox to appear that tells the user that he has to insert an anwser.
    After the user clicks ok on the msgbox, again the inputbox appears.
    Again if the user types nothing the msgbox appears, etc, etc,,,

    Can anybody help my figure out the structure of this problem.

    So far I got the followong code:

    if inputbox = "Good Anwser" then
    label.text = "Great!"
    elseif inputbox = "Wrong Anwser" then
    label.text = "Wrong!"
    else inputbox = "" then
    msgbox("you must type in an anwser")
    (how can I return to the point that the inputbox appears???)
    end if

    Thanks very much in advance for your help guys...

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

    Re: Repeating msgbox...

    Display your InputBox and get the return value into a variable. Then use a While loop to test that value and, if it is an empty string, display your MessageBox and then another InputBox. If the user enters a value then the loop will never be entered. If the loop is entered then it wil be exited as soon as the user enters a value. After the loop you can test that value returned to see if it is the correct answer or not. Note that this requires InputBox to be used exactly twice in your code. Not once and not more than twice.
    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

  3. #3
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: Repeating msgbox...

    Hi,

    You can do the same that jmc told you and just using one inputbox; instead on the WHILE loop you can use a DO loop, put the inputbox line inside your loop, asing the result to a variable and check at the end of the loop

    VB Code:
    1. do
    2.  
    3. 'put here your inputbox
    4.  
    5. loop while 'check your var to the correct value in order to exit the loop

    hope this helps
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

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

    Re: Repeating msgbox...

    Quote Originally Posted by josep
    Hi,

    You can do the same that jmc told you and just using one inputbox; instead on the WHILE loop you can use a DO loop, put the inputbox line inside your loop, asing the result to a variable and check at the end of the loop

    VB Code:
    1. do
    2.  
    3. 'put here your inputbox
    4.  
    5. loop while 'check your var to the correct value in order to exit the loop

    hope this helps
    And how exactly will the MessageBox be shown if and only if the user enters a blank value?
    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

  5. #5
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: Repeating msgbox...

    Just like that

    VB Code:
    1. Do
    2.             i = InputBox("pp")
    3.             If i = "" Then MsgBox("blank answer")
    4.         Loop While i = "" Or (i <> "g" And i <> "w")

    forgot to tell on my previous post just checking the blank answer for msgbox display
    Useful links:DB connection strings ADO.NET VB.NET Tutorials

    • Don't forget to close the thread if solved
    • If this post helps you rate it

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

    Re: Repeating msgbox...

    That'll do it. I guess I was assuming only testing the return value once, but there is really nothing to stop you testing it twice.
    VB Code:
    1. Dim answer As String = InputBox("Prompt")
    2.  
    3. While answer = String.Empty
    4.     MessageBox.Show("Message")
    5.     answer = InputBox("Prompt")
    6. End While
    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: Repeating msgbox...

    Thank you very much guys.

    your anwser helped great.

    Thanks!!!

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