MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2002, 09:30 AM   #1
LMF
Board Regular
 
Join Date: Mar 2002
Posts: 73
Default

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

LMF is offline   Reply With Quote
Old Apr 6th, 2002, 09:48 AM   #2
LMF
Board Regular
 
Join Date: Mar 2002
Posts: 73
Default

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

i am still stuck, pls give me some help
LMF is offline   Reply With Quote
Old Apr 6th, 2002, 10:13 AM   #3
LMF
Board Regular
 
Join Date: Mar 2002
Posts: 73
Default

pls help
LMF is offline   Reply With Quote
Old Apr 6th, 2002, 10:15 AM   #4
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Quote:
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 ]
dk is offline   Reply With Quote
Old Apr 6th, 2002, 11:17 AM   #5
Anne Troy
MrExcel MVP
 
Anne Troy's Avatar
 
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,512
Default

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
Anne Troy is offline   Reply With Quote
Old Apr 6th, 2002, 11:22 AM   #6
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

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 ]
Mark O'Brien is offline   Reply With Quote
Old Apr 6th, 2002, 11:59 AM   #7
smozgur
BatCoder
 
Join Date: Feb 2002
Location: Turkey
Posts: 764
Default



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 ]
smozgur is offline   Reply With Quote
Old Apr 6th, 2002, 12:09 PM   #8
smozgur
BatCoder
 
Join Date: Feb 2002
Location: Turkey
Posts: 764
Default

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


smozgur is offline   Reply With Quote
Old Apr 6th, 2002, 12:13 PM   #9
LMF
Board Regular
 
Join Date: Mar 2002
Posts: 73
Default

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

i just tested it...

thanks dk
LMF is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:11 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes