Results 1 to 10 of 10

Thread: [RESOLVED] [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    62

    Resolved [RESOLVED] [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    I should know how to do this but the last I use it was some years ago with VB6.
    Give a request for input of information through an inputbox how do I ask “ Do you want to do that again “ thru a messagebox and continue to do this until NO is selected on the messagebox?

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

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    You answered your own question:
    continue to do this until NO is selected on the messagebox?
    vb.net Code:
    1. Do
    2.     'Something
    3. Loop Until MessageBox.Show("Again?", ...) = Windows.Forms.DialogResult.No
    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

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    62

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    Thanks for the prompt reply. I added your code to mine, see code below.

    Private Sub ButAddWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAddWord.Click
    Dim Input As String
    Do
    Input = InputBox("Enter a new word", "Update list", String.Empty)
    If Input <> String.Empty Then ListBox1.Items.Add(Input)
    Loop Until MessageBox.Show("Another?")=Windows.Forms.DialogResult.No
    End Sub

    When I run this it work, but only displays an ok messagebox not yes/no.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    Have a look at the different overloads for the MessageBox.Show method on MSDN.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    MessageBox.Show's overloads let you specify MessageBoxButtons. This is an enum. You want MessageBoxButtons.YesNo.

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    62

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    I have looked at the messagebox overloads but can't see one offering a Yes/No button.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    Have a look at this list of overloads.
    Read the description for the 5th overload
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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

    Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    You couldn't have added my code because my code won't work as is. My code contains a comma and an ellipsis, which implies that you're supposed to add the rest. If you just take notice of Intellisense as you type it will give you access to all overloads, plus it will help you enter enumerated values.
    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

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    62

    Re:[2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    Thanks for the help. With all the advice I have sorted the problem as shown below:

    Private Sub ButAddWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButAddWord.Click
    Dim Input As String
    Dim result As MsgBoxResult
    Do
    Input = InputBox("Enter a new word", "Update list", String.Empty)
    If Input <> String.Empty Then ListBox1.Items.Add(Input)
    result = MessageBox.Show("Another word?", "Data entry", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
    Loop Until result = Windows.Forms.DialogResult.No
    End Sub

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

    Re: [RESOLVED] [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox

    You're now using YesNoCancel, but that's the wrong choice. You're only opting out of the loop if the user presses No, so what's Cancel for? If the user presses Cancel you're prompting them for another word, which doesn't really make sense.

    Also, why use the MessageBox at all when there's a Cancel button on the InputBox? Surely if the user hits the Cancel button on the InputBox it means they don't want to enter another word.
    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

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