| | |
Looping a message box vb net ?
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 14
Reputation:
Solved Threads: 0
I have a listbox in my program and a command button. When the user selects an item form the listbox and clicks the command button, a message box is shown which asks the user to confirm selection and has yes and no options to enable this.
If the user clicks yes it will accept the selection, i can do this.
I want the program to be able to offer the message box for confirmation two times after it has first been shown and after the no button is selected each time i want it to go back to the listbox to allow selection. On the third time i want it to automatically accept the choice and not offer confirmation as before.
If the user clicks yes it will accept the selection, i can do this.
I want the program to be able to offer the message box for confirmation two times after it has first been shown and after the no button is selected each time i want it to go back to the listbox to allow selection. On the third time i want it to automatically accept the choice and not offer confirmation as before.
VB.NET Syntax (Toggle Plain Text)
Dim b As Integer Dim inputno As Integer inputno = 3 Dim dlgRes As DialogResult dlgRes = MessageBox.Show(" Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo) If dlgRes = DialogResult.Yes Then listboxselect.SelectedIndex = selecteditem End If
Last edited by Ancient Dragon; Feb 19th, 2009 at 5:49 pm. Reason: correct code tags
k so you want: User -> selection -> confirmation message ->user says no -> back to selecttion -> confirmation message -> user says no -> back to selection -> no confirmation and just accepts?
if so this is the rough outline of how you do it:
while tries <= 2
msgbox("are you sure?")
tries = tries + 1
end while
if so this is the rough outline of how you do it:
while tries <= 2
msgbox("are you sure?")
tries = tries + 1
end while
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 10
You would probably have to play with the count and where the message box is displayed to get this to be exactly what you want, but I think something like this should work.
vb Syntax (Toggle Plain Text)
Public Class Form1 Dim numTries As Short Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListBox1.Items.Add("a") ListBox1.Items.Add("b") ListBox1.Items.Add("c") numTries = 0 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ListBox1.SelectedIndex <> -1 Then Dim diagResult As DialogResult = MessageBox.Show("Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo) If diagResult <> DialogResult.Yes And numTries < 3 Then ListBox1.Focus() numTries = numTries + 1 ElseIf diagResult = DialogResult.Yes Or numTries >= 3 Then MessageBox.Show("Do whatever") End If End If End Sub End Class
![]() |
Similar Threads
- Tutorial: Understanding ASP classes (ASP)
Other Threads in the VB.NET Forum
- Previous Thread: [request] how to connect remotely to access db
- Next Thread: need help how to connect database to vb.net
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary bing box button buttons click code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists file-dialog firewall folder google hardcopy image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net networking opacity output peertopeervideostreaming picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog serial sqldatbase storedprocedure string temp text textbox timer toolbox updown useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





