![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Posts: 73
|
strange that + does not work, but * bloody work which I don't need...
i am still stuck, pls give me some help |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 73
|
pls help
|
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Quote:
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,512
|
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.
__________________
~Anne Troy |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Why not use another variable to hold the total? e.g.
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 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
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 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
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 |
|
Board Regular
Join Date: Mar 2002
Posts: 73
|
but I have just tried dk method , and he is right, it works.
i just tested it... thanks dk |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|