If...Then

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michels287
    New Member
    • Mar 2008
    • 20

    If...Then

    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
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    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.

    Comment

    • anuragshrivastava64
      New Member
      • Jan 2007
      • 66

      #3
      [CODE=vb]Dim bYes As Boolean
      Dim bYesNo As Boolean

      Private Sub cmdNo_Click()
      If bYes Then bYesNo = Not bYesNo
      End Sub

      Private Sub cmdYes_Click()
      bYes = Not bYes
      If bYesNo Then
      Text1 = 30
      bYes = False
      bYesNo = False
      End If
      End Sub[/CODE]
      Last edited by debasisdas; Mar 18 '08, 05:44 AM. Reason: added code=vb tags

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

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

        [code=vb]
        Private Sub cmdNo_Click()
        If bYes Then
        If bYesNo Then
        bYes = False
        bYesNo = False
        Else
        bYesNo = True
        End If
        Else
        bYes = False
        bYesNo = False
        End If
        End Sub
        [/code]

        Rest of the code remains same..

        REgards
        Veena

        Comment

        • michels287
          New Member
          • Mar 2008
          • 20

          #5
          Thank you so very much.

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

          Thanks.

          Comment

          • michels287
            New Member
            • Mar 2008
            • 20

            #6
            Here is what I have:
            [code=vb]
            Private Sub Form_Load()
            Dim bYes As Boolean
            Dim bYesNo As Boolean
            End Sub

            Private Sub cmdNo_Click()


            If List1.ListIndex > 0 Then
            List1.ListIndex = List1.ListIndex - 1
            End If

            If bYes Then
            If bYesNo Then
            bYes = False
            bYesNo = False
            Else
            bYesNo = True
            End If
            Else
            bYes = False
            bYesNo = False
            End If
            End Sub

            Private Sub cmdYes_Click()

            If List1.ListIndex < List1.ListCount - 1 Then
            List1.ListIndex = List1.ListIndex + 1
            End If

            bYes = Not bYes
            If bYesNo Then
            Text1 = 30
            bYes = False
            bYesNo = False
            End If
            End Sub[/code]

            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; Mar 18 '08, 05:45 AM. Reason: added code=vb tags

            Comment

            • anuragshrivastava64
              New Member
              • Jan 2007
              • 66

              #7
              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

              Comment

              • michels287
                New Member
                • Mar 2008
                • 20

                #8
                Originally posted by anuragshrivasta va64
                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!

                Comment

                • michels287
                  New Member
                  • Mar 2008
                  • 20

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

                  Thanks!!!!!!

                  Comment

                  • debasisdas
                    Recognized Expert Expert
                    • Dec 2006
                    • 8119

                    #10
                    Please go through the code again.

                    Comment

                    Working...