| | |
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 |
Tag cloud for VB.NET
.net .net2008 2005 2008 access account application arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web webbrowser winforms wpf year





