How do I use equal to or less then in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DAHMB
    New Member
    • Nov 2007
    • 147

    How do I use equal to or less then in VB

    I am trying to the following but it stops priot to completion:

    Code:
    ......
    Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank < 1
    stRateOfPay = "Ptlm1"
    Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank > 1 = 2 < 3
    stRateOfPay = "Ptlm2"
    ..........
    At line 3 it checks that Forms!frmOverTi me!YearsInRank is greater then 1 and stops there and fils the dtat under line 4 in my form. It is not continuing to check if it is equal to 2 and less then 3 and continuing on if it is. What am I doing wrong?????

    Thanks
    Last edited by pbmods; Jan 21 '09, 01:10 AM. Reason: Added CODE tags.
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    I think you are using the Case incorrectly. You can have

    Select Case rs!Rank
    Is = 6 'or "6" for text
    Select Case Forms!frmOverTi me!YearsInRank 'or just use If
    etc.

    Each clause in the case statement is going to compare to whatever you Select. Pretty sure you can't combine them with AND.

    Comment

    • DAHMB
      New Member
      • Nov 2007
      • 147

      #3
      It actually looks like this:


      Code:
      Select Case True
      Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank < 1
      stRateOfPay = "Ptlm1"
      Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank > 1 = 2 < 3
      stRateOfPay = "Ptlm2"
      Any ideas?
      Last edited by pbmods; Jan 21 '09, 01:10 AM. Reason: Fixed CODE tags.

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Let me try that again with code tags.

        Code:
        Select Case rs!Rank
            Is = 6 'or "6" for text
                Select Case Forms!frmOverTime!YearsInRank 'or just use If
            etc.
        Sorry I hit TAB the first time and posted prematurely.

        Comment

        • DAHMB
          New Member
          • Nov 2007
          • 147

          #5
          My problem is with the comparison at the end it s not fully checking the value of Forms!frmOverTi me!YearsInRank to se if it is less than 1 or equal or greater than 2 but less than 3.

          Comment

          • ChipR
            Recognized Expert Top Contributor
            • Jul 2008
            • 1289

            #6
            You might be able to put And Forms!frmOverTi me!YearsInRank in between each of those, or just write an if statement. The syntax is just wrong. I've never used Select Case True. Is that a common practice?

            Comment

            • DAHMB
              New Member
              • Nov 2007
              • 147

              #7
              I have no idea, I was using elseIf but someone else pointed me to use select case.

              Comment

              • ChipR
                Recognized Expert Top Contributor
                • Jul 2008
                • 1289

                #8
                Actually, why would you say "greater than 1 and equal to 2 and less than 3" instead of simply "equal to 2"?

                Comment

                • DAHMB
                  New Member
                  • Nov 2007
                  • 147

                  #9
                  good point I was using months before and canned that idea. I am movving on to another angle.

                  Thanks

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32661

                    #10
                    Originally posted by ChipR
                    I've never used Select Case True. Is that a common practice?
                    No Chip.

                    It is however very flexible and powerful ;)

                    Select Case is a very flexible and clear way of splitting the logic. It can handle multiple splits more clearly than multiple Ifs or even ElseIfs.

                    What can sometimes be a limitation is that the checks are not always done on the same items, even when the splitting of the logic all happens in one place. This is where the Select Case True comes in.

                    Think about it. The first of the Case statements to resolve to True will be selected when run. Elegant and supremely flexible.

                    Dan's code was actually quite valid (in its concept at least).

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32661

                      #11
                      Originally posted by DAHMB
                      It actually looks like this:
                      Code:
                      Select Case True
                      Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank < 1
                      stRateOfPay = "Ptlm1"
                      Case rs!Rank = "6" And Forms!frmOverTime!YearsInRank > 1 = 2 < 3
                      stRateOfPay = "Ptlm2"
                      Any ideas?
                      I'm assuming you're talking about your line #4 here?

                      Can you say exactly what you're looking for in Forms!frmOverTi me!YearsInRank? Can we also assume that this figure will be integral (whole numbers only)?

                      Comment

                      • AXESMI59
                        New Member
                        • Sep 2008
                        • 10

                        #12
                        In Line 4, do all of those conditions need to be true? PErhaps you need to break that up with an AND or an OR

                        Forms!frmOverTi me!YearsInRank > 1 AND/OR Forms!frmOverTi me!YearsInRank = 2 AND/OR Forms!frmOverTi me!YearsInRank < 3

                        Where AND/OR is either AND or OR. Just a thought.

                        Steve

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32661

                          #13
                          Steve's point is very likely to be right for your situation. Clarification of my earlier point would help us to be sure.

                          Assuming then that it is so for now, this leaves us looking to find a way to reduce all the referencing in Forms!frmOverTi me!YearsInRank.

                          Would this code be running within the frmOverTime module anyway by any chance? If so, then Me.YearsInRank (or even more simply YearsInRank alone) would be a simpler and shorter way of referring to the same object.

                          Comment

                          Working...