sam17
asked on
VB: label
I have the following statement:
lblNetCharge.Caption = (DAYCHARGE * NumberOfDays) + (MILESDRIVENCHARGE * MilesDriven)
with
NumberOfDays = Val(txtNumberOfDays.Text)
and
MilesDriven = Val(lblMilesDriven)
the 1st part of the calculation worked fine but the other one gave me a "0"
But when i replace (MILESDRIVENCHARGE * MilesDriven) by (MILESDRIVENCHARGE * Val(lblMilesDriven))
it works fine.
how can i use a variable for the label value?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thnx a lot
what ur saying is that we can use the val() statement for a texbox only and not for the label..?
and the lbl.caption stt for the label?
what ur saying is that we can use the val() statement for a texbox only and not for the label..?
and the lbl.caption stt for the label?
The Val statement can be used for a label, the point I make regarding procedure in coding is that it is much easier to write programs that are a step by step process, as opposed to attempting to cram as many steps as possible in each line of code. You will be a much more succesful (and sane) programmer if you attempt to keep things simple, and organized. Debuging is much easier since each line of code is only providing one new step.
I hope this was helpful.
I hope this was helpful.
lblNetCharge.Caption = (DAYCHARGE * NumberOfDays) + (MILESDRIVENCHARGE * MilesDriven)
MilesDriven = Val(lblMilesDriven)
so that MilesDrive is UNCALCULATED(hence value = 0) when you try to use it.
change to:
MilesDriven = Val(lblMilesDriven)
lblNetCharge.Caption = (DAYCHARGE * NumberOfDays) + (MILESDRIVENCHARGE * MilesDriven)
and it SHOULD be fine.
AW