Solved

Case Stament to compare numbers

Posted on 2009-06-29
7
179 Views
Last Modified: 2012-05-07
I need to have a case statement to compare a variable and see if it is between two numbers.

i.e

Select Case PageCount

case (between 0 an 100
 postage = 1.10
case (between 101 and 200)
 Postage = 2.20
case else
 postage 5.50

end select

How do I accomplish this
0
Comment
Question by:BPWALKIN
  • 3
  • 2
  • 2
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24739489
this should do
Select Case PageCount 
case is => 0 and is <= 100
 postage = 1.10
case is > 100 and is <= 200
 Postage = 2.20
case else
 postage 5.50 
end select

Open in new window

0
 

Author Comment

by:BPWALKIN
ID: 24739509
I am using VB6 I am getting a syntax error with that code.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24739581
where exactly, and which error?

alternative:
Select Case 
case PageCount => 0 and PageCount <= 100
 postage = 1.10
case PageCount > 100 and PageCount <= 200
 Postage = 2.20
case else
 postage 5.50 
end select

Open in new window

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24739741
How about?
        Select Case PageCount
            Case 0 To 100
                postage = 1.10
 
            Case 101 To 200
                postage = 2.20
 
            Case Else
                postage = 5.50
 
        End Select

Open in new window

0
 

Author Comment

by:BPWALKIN
ID: 24739764
regardless of the value in pagecount I am getting 5.5 in my postage value.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24739781
Who was that directed at?...and is PageCount a NUMERIC variable or a STRING?
0
 

Author Comment

by:BPWALKIN
ID: 24739787
Numeric , last message was posted to angell
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question