[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?
Re: [2005] Repeated Inputs to an inputbox until NO is selected on a messagebox
You answered your own question:
Quote:
continue to do this until NO is selected on the messagebox?
vb.net Code:
Do
'Something
Loop Until MessageBox.Show("Again?", ...) = Windows.Forms.DialogResult.No
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.
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.
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.
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.
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 ;)
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.
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
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.