Results 1 to 5 of 5

Thread: Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759
    Hi Everyone,

    I currently have a Select Case statement with 3 cases in it. First, if a numbered amount is less than or equal to 10 then a cerain price is applied, say $12.00. It is the second and third cases that I am having problems with. I want to set it up so that if the numbered amount is greater than 10 but less than 20 then the amount applied is $12.00 plus $.50 for every number over 10. For example, if the number was 11 then the amount would be $12.50 , 12 would be $13.00, etc. Once you get over 20 then the cost would be $12.00 plus $.25. Does anyone know an easy way to set this up? I would appreicate any help. Thank you.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    Howdy,

    I haven't checked the calculations as I'm guessing that your problem stems from the syntax for the case statement. But this should work

    Code:
        x = 1
        
        Select Case x
        Case Is <= 10
            Debug.Print "$12"
            
        Case Is > 10, Is <= 20
            Debug.Print "$" + CStr(12 + 0.5 * (x - 10))
            
        Case Is > 20
            Debug.Print "$" + CStr(12 + 0.25 * (x - 10))
            
        End Select
    I hope this helps,

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759
    Hi SurfDemon,

    I guess I am a little confused. What does the x - 10 do in the equation. I want to add .50 to every number above 10. For examples, if the number is 11 then the amount would be 12.50, if the amount was 12 the the amount would be 13.00, etc. I cannot get your formula to work correctly.

  4. #4
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Does this work?

    Code:
    Function calPrice(num As Double) As Double
    If num > 0 Then ' Error check To prevent neg numbers
        
        Select Case num
            Case Is <= 10
                calPrice = 12
    
            Case Is <= 20
                calPrice = 12 + Clng(num - 10) * 0.5
    
            Case Else
                calPrice = 12 + Clng(num - 10) * 0.25
        End Select
        
    End If
    End Function
    
    Private Sub Command1_Click()
    MsgBox FormatCurrency(calPrice(12), 2)
    End Sub

  5. #5
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    X is just the number of items sold. I was just using it to illustrate the case statement. I thought that was where your problem lay.

    The statement


    CStr(12 + 0.5 * (x - 10))

    is just a formula. So if you replace X with 11 you get

    12 +0.5 * (11-10)

    which =

    12 + 0.5 * 1

    =

    12 +0.5

    = 12.5 the correct number.


    If you aren't dealing with whole numbers, then see JamesM's response.

    Cheers,

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width