|
-
Feb 15th, 2009, 07:18 AM
#1
Thread Starter
Member
[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?
-
Feb 15th, 2009, 07:21 AM
#2
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:
Do 'Something Loop Until MessageBox.Show("Again?", ...) = Windows.Forms.DialogResult.No
-
Feb 15th, 2009, 08:18 AM
#3
Thread Starter
Member
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.
-
Feb 15th, 2009, 08:23 AM
#4
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.
-
Feb 15th, 2009, 08:31 AM
#5
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.
-
Feb 15th, 2009, 09:06 AM
#6
Thread Starter
Member
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.
-
Feb 15th, 2009, 09:17 AM
#7
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
-
Feb 15th, 2009, 04:35 PM
#8
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.
-
Feb 15th, 2009, 06:03 PM
#9
Thread Starter
Member
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
-
Feb 15th, 2009, 06:23 PM
#10
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.
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
|