943,535 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1268
  • VB.NET RSS
Feb 19th, 2009
0

Looping a message box vb net ?

Expand Post »
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.

VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
asif786 is offline Offline
19 posts
since Dec 2008
Feb 20th, 2009
0

Re: Looping a message box vb net ?

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
Reputation Points: 10
Solved Threads: 8
Junior Poster
toko is offline Offline
104 posts
since Aug 2007
Feb 20th, 2009
1

Re: Looping a message box vb net ?

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)
  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
Reputation Points: 23
Solved Threads: 10
Light Poster
bcasp is offline Offline
45 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: [request] how to connect remotely to access db
Next Thread in VB.NET Forum Timeline: need help how to connect database to vb.net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC