I need help urgently!!! please help me!!! or pls read in!!!

LMF

Board Regular
Joined
Mar 16, 2002
Messages
73
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
strange that + does not work, but * bloody work which I don't need...

i am still stuck, pls give me some help
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
Why not use another variable to hold the total? e.g.<pre>

TotalCost = Cost1 + Cost2

If TotalCost > "40" Then
Error = "cost too much"
Else</pre>

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

HTH

_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-04-06 10:23
 
Upvote 0
:)

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
 
Upvote 0
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
 
Upvote 0
but I have just tried dk method , and he is right, it works.

i just tested it...

thanks dk :)
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top