## Mathematical Formula

## Mathematical Formula

(OP)

Hello all.

I have a formula that calculates a price based on the number of miles.

Here is the formula:

For the first 1 mile - charge £19 flat rate

For the next 29 miles - charge £1.50 for every 1 mile

For the next 20 miles - charge £1.25 for every 1 mile

For the rest - charge £1.00 for every 1 mile

Here are some valid results for testing:

1 mile = £19

5 miles = £25

10 miles = £32.50

20 miles = £47.50

50 miles = £87.50

100 miles = £137.50

I think this can be acheived using a Select Case.

I have tried the following:

But already I'm stuck (Expected ')' on bold line..

I'm not sure if this is the best way to go about things (logically)...

Really could use some assistance.

Thanks

I have a formula that calculates a price based on the number of miles.

Here is the formula:

For the first 1 mile - charge £19 flat rate

For the next 29 miles - charge £1.50 for every 1 mile

For the next 20 miles - charge £1.25 for every 1 mile

For the rest - charge £1.00 for every 1 mile

Here are some valid results for testing:

1 mile = £19

5 miles = £25

10 miles = £32.50

20 miles = £47.50

50 miles = £87.50

100 miles = £137.50

I think this can be acheived using a Select Case.

I have tried the following:

#### CODE

<% Mileage = 10Sub GetPrice(ByVal Mileage As Integer)Select Case Mileage Case Is <=1 Price = 19 Case Is 1 To 30 Price = 19 + ((Mileage - 1) * 1.50) End Select End Sub Response.Write Price %>

But already I'm stuck (Expected ')' on bold line..

I'm not sure if this is the best way to go about things (logically)...

Really could use some assistance.

Thanks

## RE: Mathematical Formula

look at the following (warning: untested!). It might not look super elegant but it should do the trick just fine:

## CODE

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)

Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

## RE: Mathematical Formula

My actual formula is a bit more complex so I was hoping for something a little easier to read and edit.

I was hoping for a clear distinction between the prices to be charged and the additional miles to be added.

That way I could add further steps to my formula quite easily.

## RE: Mathematical Formula

B:This code

## CODE --> basic

Is ALSO Visual Basic NOT VbScript

Select .. Case in VbScript can ONLY check for

equality, it cannot do comparison testingChris.

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum

## RE: Mathematical Formula

## RE: Mathematical Formula

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)

Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

## RE: Mathematical Formula

axLWYou are not going to get a "simple" snippet of code for what you hope to do, the vbscript in ASP does not have the capabilities to parse your data and make such 'decisions'. It is going to require a call to a very convoluted function or instantiate a object class that encapsulates several functions and properties.

Chris.

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum

## RE: Mathematical Formula

Chris.

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum

## RE: Mathematical Formula

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum

## RE: Mathematical Formula

## RE: Mathematical Formula

## CODE

## RE: Mathematical Formula

ASP Class encapsulation (called MileageCalcs file name mileage-calcs.asp)

## CODE --> ASP(vbscript)

Bit more flexible than a fixed function.

If you want to set any of the values when the class is instantiated you can do so in the Initialize sub

How to include and use is below;

## CODE --> ASP(vbscript)

Chris.

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum

## RE: Mathematical Formula

Let me get my teeth into it :)

## RE: Mathematical Formula

What do I owe you?!

## RE: Mathematical Formula

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)

Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

## RE: Mathematical Formula

A grand total of nothing at all, I don't code for financial gain these days, it's just good 'brain exercise' :)

Indifference will be the downfall of mankind, but who cares?

Time flies like an arrow, however, fruit flies like a banana.Webmaster Forum