Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Case Stament to compare numbers

Posted on 2009-06-29
7
Medium Priority
?
206 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 143

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 143

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

963 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