Thanks:  0
Likes:  0

1. okay, i am doing this as ASP, but very similar to excel, so i think some1 may know about this simple stuff, but i am stuck on it. pls help

If Request("Number1") = "303" Then
Cost1 = "16"
End If
If Request("Number2") = "304" Then
Cost2 = "30"
End If

This bit is fine, but I need to add the 2 costs together to write another if function, saying if the 2 costs together cost more than certain amount, then do something... how do u do adding in an if function???

If Cost1 + Cost2 > "40" Then
Error = "cost too much"
Else

but this does not work, can any help me with this, i got the same problem in excel as well, but pls remmeber this is asp

pls help me,

gamestore@hotmail.com

2. strange that + does not work, but * bloody work which I don't need...

i am still stuck, pls give me some help

3. pls help

4. If Request("Number1") = "303" Then
Cost1 = "16"
End If
If Request("Number2") = "304" Then
Cost2 = "30"
End If

If Cost1 + Cost2 > "40" Then
Error = "cost too much"
Else
Hi,

You're using strings (text) for your costs. That won't help. Use something like this:

If Request("Number1") = "303" Then
Cost1 = 16
End If
If Request("Number2") = "304" Then
Cost2 = 30
End If

As for the second bit - have you missed some code out of your post or is this the code in full? If so the you're missing an End If. If you use an If statement which is not all on one line then you need to end it with an End If e.g.

If Cost1 + Cost2 > 40 Then
Error = "cost too much"
End If

HTH,
Dan

[ This Message was edited by: dk on 2002-04-06 09:18 ]

5. I've called in an ASPer that is familiar with Excel. Might take a bit till he gets here.

I was on the same track that you're using quotes on numbers when quotes are generally referring to text.

6. Why not use another variable to hold the total? e.g.

```

TotalCost = Cost1 + Cost2

If TotalCost > "40" Then
Error = "cost too much"
Else ```

It could be that the If statement is having problems with the summation.

HTH

_________________
[b] Mark O'Brien

[ This Message was edited by: Mark O'Brien on 2002-04-06 10:23 ]

7. If Request("Number1") = "303" Then
Cost1 = "16"
End If
If Request("Number2") = "304" Then
Cost2 = "30"
End If

TotalCost=cint(Cost1)+cint(Cost2)

Use TotalCost however you need as number now.

I mean :

If cint(Cost1) + cint(Cost2) > 40 Then
Error = "cost too much"
Else

regards

_________________
Oz ~ TheWordExpert

[ This Message was edited by: smozgur on 2002-04-06 11:01 ]

8. A question:

Why do you set Cost1 and Cost2 as string instead directly numbers?

Another way of solving it, you remember what we do sometimes in Excel:

Cost1*1 + Cost2*1

if they are still strings. Remember (+) isnot arithmetic operator as first if parameters are string. But (*) is always an arithmetic. So if you use (*) it will be executed as first and *1 will convert strings to numbers and then (+) will run as arithmatic operator.

Regards

9. but I have just tried dk method , and he is right, it works.

i just tested it...

thanks dk

## User Tag List

#### Posting Permissions

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