Solved

Case Stament to compare numbers

Posted on 2009-06-29
7
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 86

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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.
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…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

623 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