Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

If...Then

Question posted by: michels287 (Newbie) on March 16th, 2008 05:56 AM
Maybe someone can help me here.

I have two command buttons: "yes" and "no".

How can I create a way so that when the user selects "yes" then "no" then "yes" again the number 30 is store in a text box?

The buttons have to be pushed in that exact order in order for the number to appear.

Thanks for your help.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
debasisdas's Avatar
debasisdas
Moderator
6,450 Posts
March 17th, 2008
06:29 AM
#2

Re: If...Then
Kindly post what you have tried so far.

Try to set some flag on each button click and check the same on other button clicks.

Reply
anuragshrivastava64's Avatar
anuragshrivastava64
Member
61 Posts
March 17th, 2008
07:45 AM
#3

Re: If...Then
Code: ( text )
  1. Dim bYes As Boolean
  2. Dim bYesNo As Boolean
  3.  
  4. Private Sub cmdNo_Click()
  5. If bYes Then bYesNo = Not bYesNo
  6. End Sub
  7.  
  8. Private Sub cmdYes_Click()
  9.     bYes = Not bYes
  10.     If bYesNo Then
  11.         Text1 = 30
  12.         bYes = False
  13.         bYesNo = False
  14.     End If
  15. End Sub

Last edited by debasisdas : March 18th, 2008 at 05:44 AM. Reason: added code=vb tags
Reply
QVeen72's Avatar
QVeen72
Expert
1,248 Posts
March 17th, 2008
08:28 AM
#4

Re: If...Then
Hi,

Slight Modofication in Anurag's code..
because, if user Clicks No twice, then the Falg need to be reset..

Code: ( text )
  1. Private Sub cmdNo_Click()
  2. If bYes Then
  3.     If bYesNo Then
  4.        bYes = False
  5.        bYesNo = False
  6.     Else
  7.         bYesNo = True
  8.     End If
  9. Else
  10.    bYes = False
  11.    bYesNo = False
  12. End If
  13. End Sub


Rest of the code remains same..

REgards
Veena

Reply
michels287's Avatar
michels287
Newbie
15 Posts
March 18th, 2008
02:07 AM
#5

Re: If...Then
Thank you so very much.

I will try executing this and let everyone know how I do.

Thanks.

Reply
michels287's Avatar
michels287
Newbie
15 Posts
March 18th, 2008
02:21 AM
#6

Re: If...Then
Here is what I have:
Code: ( text )
  1. Private Sub Form_Load()
  2. Dim bYes As Boolean
  3. Dim bYesNo As Boolean
  4. End Sub
  5.  
  6. Private Sub cmdNo_Click()
  7.  
  8.  
  9.    If List1.ListIndex > 0 Then
  10.         List1.ListIndex = List1.ListIndex - 1
  11.         End If
  12.  
  13. If bYes Then
  14.     If bYesNo Then
  15.        bYes = False
  16.        bYesNo = False
  17.     Else
  18.         bYesNo = True
  19.     End If
  20. Else
  21.    bYes = False
  22.    bYesNo = False
  23. End If
  24. End Sub
  25.  
  26. Private Sub cmdYes_Click()
  27.  
  28. If List1.ListIndex < List1.ListCount - 1 Then
  29.     List1.ListIndex = List1.ListIndex + 1
  30. End If
  31.    
  32. bYes = Not bYes
  33. If bYesNo Then
  34. Text1 = 30
  35. bYes = False
  36. bYesNo = False
  37. End If
  38. End Sub


The Yes and No buttons also cycle through the listbox. Yes moves the list to the next item, and No selects the previous item.

The number still didn't appear. What could I be doing wrong?

Thanks!!

Last edited by debasisdas : March 18th, 2008 at 05:45 AM. Reason: added code=vb tags
Reply
anuragshrivastava64's Avatar
anuragshrivastava64
Member
61 Posts
March 18th, 2008
03:18 AM
#7

Re: If...Then
You have given the declaration of bYes and bNo in Form Load Event which makes them private for the procedure Form_Load

Try declaring them in General Declaration Section

Reply
michels287's Avatar
michels287
Newbie
15 Posts
March 18th, 2008
04:16 AM
#8

Re: If...Then
Quote:
Originally Posted by anuragshrivastava64
You have given the declaration of bYes and bNo in Form Load Event which makes them private for the procedure Form_Load

Try declaring them in General Declaration Section



Brilliant! Works perfectly. Thanks again for the help!

Reply
michels287's Avatar
michels287
Newbie
15 Posts
July 3rd, 2008
10:13 PM
#9

Re: If...Then
This code works well for me, but can someone explain to me HOW it works?

Thanks!!!!!!

Reply
debasisdas's Avatar
debasisdas
Moderator
6,450 Posts
July 4th, 2008
04:19 AM
#10

Re: If...Then
Please go through the code again.

Reply
Reply
Not the answer you were looking for? Post your question . . .
184,211 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Visual Basic Forum Contributors