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: asif786 is an unknown quantity at this point 
Solved Threads: 0
asif786 asif786 is offline Offline
Newbie Poster

Looping a message box vb net ?

 
0
  #1
Feb 19th, 2009
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.

  1. Dim b As Integer
  2. Dim inputno As Integer
  3. inputno = 3
  4. Dim dlgRes As DialogResult
  5.  
  6. dlgRes = MessageBox.Show(" Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo)
  7.  
  8. If dlgRes = DialogResult.Yes Then
  9. listboxselect.SelectedIndex = selecteditem
  10. End If
Last edited by Ancient Dragon; Feb 19th, 2009 at 5:49 pm. Reason: correct code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 89
Reputation: toko is an unknown quantity at this point 
Solved Threads: 8
toko's Avatar
toko toko is offline Offline
Junior Poster in Training

Re: Looping a message box vb net ?

 
0
  #2
Feb 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: bcasp is an unknown quantity at this point 
Solved Threads: 10
bcasp bcasp is offline Offline
Light Poster

Re: Looping a message box vb net ?

 
1
  #3
Feb 20th, 2009
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.

  1. Public Class Form1
  2.  
  3. Dim numTries As Short
  4.  
  5. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6. ListBox1.Items.Add("a")
  7. ListBox1.Items.Add("b")
  8. ListBox1.Items.Add("c")
  9.  
  10. numTries = 0
  11. End Sub
  12.  
  13. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  14. If ListBox1.SelectedIndex <> -1 Then
  15. Dim diagResult As DialogResult = MessageBox.Show("Do you wish to select this item", "Confirm choice", MessageBoxButtons.YesNo)
  16. If diagResult <> DialogResult.Yes And numTries < 3 Then
  17. ListBox1.Focus()
  18. numTries = numTries + 1
  19. ElseIf diagResult = DialogResult.Yes Or numTries >= 3 Then
  20. MessageBox.Show("Do whatever")
  21. End If
  22. End If
  23. End Sub
  24. End Class
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC