Connecting Tech Pros Worldwide Forums | Help | Site Map

If...Then

Newbie
 
Join Date: Mar 2008
Posts: 20
#1: Mar 16 '08
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.

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#2: Mar 17 '08

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.
Member
 
Join Date: Jan 2007
Posts: 65
#3: Mar 17 '08

re: If...Then


Expand|Select|Wrap|Line Numbers
  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
QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#4: Mar 17 '08

re: If...Then


Hi,

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

Expand|Select|Wrap|Line Numbers
  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
  14.  
Rest of the code remains same..

REgards
Veena
Newbie
 
Join Date: Mar 2008
Posts: 20
#5: Mar 18 '08

re: If...Then


Thank you so very much.

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

Thanks.
Newbie
 
Join Date: Mar 2008
Posts: 20
#6: Mar 18 '08

re: If...Then


Here is what I have:
Expand|Select|Wrap|Line Numbers
  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!!
Member
 
Join Date: Jan 2007
Posts: 65
#7: Mar 18 '08

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
Newbie
 
Join Date: Mar 2008
Posts: 20
#8: Mar 18 '08

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!
Newbie
 
Join Date: Mar 2008
Posts: 20
#9: Jul 3 '08

re: If...Then


This code works well for me, but can someone explain to me HOW it works?

Thanks!!!!!!
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,509
#10: Jul 4 '08

re: If...Then


Please go through the code again.
Reply