|
-
Mar 27th, 2010, 01:19 AM
#1
Thread Starter
Lively Member
If statement problem
This should be easy but, I have a shipping system, where the user picks a shipment method, and a shipment weight must be based off the shipment method chosen. i.e If the user chooses 'Standard Air', which is on a drop down list in a combo box, the consignment weight must be =>1 and <1000.
I have made a variable, dConsignWeight as Double, and converted the textbox to a double with Cdbl(txtConsignWeight.Text).
Then I try to create the If statement.
If cmbShipmentMethod.Text = "Standard Air" Then
dConsignWeight >=1
This is where I get an error? What am I doing wrong? thanks.
-
Mar 27th, 2010, 01:37 AM
#2
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Mar 27th, 2010, 01:41 AM
#3
Thread Starter
Lively Member
Re: If statement problem
If I try dConsignWeight >= 1 it says expression not a method
-
Mar 27th, 2010, 01:54 AM
#4
Re: If statement problem
Yes just saw it.
Then
dConsignWeight >=1 you are trying to assign >=1 to dConsignWeight.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Mar 27th, 2010, 01:58 AM
#5
Thread Starter
Lively Member
Re: If statement problem
so how do I code it that dConsignWeight must be >=1 o.o
-
Mar 27th, 2010, 02:03 AM
#6
Re: If statement problem
You cannot assign a value that you don't know exactly what value it is.
A value has a value it cannot be >= or <= .
You can evaluate the value only.P.E. saying
If cmbShipmentMethod.Text = "Standard Air" and dConsignWeight >=1
but you cannot assign dConsignWeight >=1.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Mar 27th, 2010, 02:15 AM
#7
Frenzied Member
Re: If statement problem
I am assuming you have different rates based on weights,
>=1 and <1000 is a certain amount ?
>=1000 and <2000 is a certain amount ? etc....
If the way I have explained it is true, then assign the amount to the range
if dConsignWeight >=1 and <1000 then
amount = 50.00
then refer to amount
-
Mar 27th, 2010, 02:30 AM
#8
Re: If statement problem
if dConsignWeight >=1 and dConsignWeight <1000
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Mar 27th, 2010, 05:55 AM
#9
Hyperactive Member
Re: If statement problem
Just to be more clear.. you have to place if inside an if (in short.. nested if..)
Code:
If cmbShipmentMethod.Text = "Standard Air" Then
if dConsignWeight >=1 and dConsignWeight <1000
'-- do bla bla...
end if
end if
The Difference between a Successful person and others is not a Lack of Knowledge,
But rather a Lack of WILL 
-
Mar 27th, 2010, 01:39 PM
#10
Re: If statement problem
Actually it's better to have the "and's" instead of another if.
That way you will not have to also parse the second if.
In this example it is ok but if you had many conditions to check then i wouldn't recommend nested if's.It will slow your program down.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Mar 27th, 2010, 01:58 PM
#11
Re: If statement problem
 Originally Posted by sapator
Actually it's better to have the "and's" instead of another if.
That way you will not have to also parse the second if.
In this example it is ok but if you had many conditions to check then i wouldn't recommend nested if's.It will slow your program down.
What you say is just the opposite of what actually is.
Nested IFs won't slow down your program. However a single IF with many conditions with AND operator would definitely slow down the program. This is because nexted IFs don't cause all conditions to be evaluated while a single IF with many conditions joined with AND operator must evaluate all conditions irrespective.
Nested IFs make the code lines longer. But some people find it easier to read and maintain that way. So I won't comment on that aspect, as it is a matter of personal preference.
If you want to use a single IF with multiple conditions, consider using the new ANDALSO / ORELSE operators to join the conditions. They cause short-circuiting between the conditions and act same as nested IFs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|