Link to home
Start Free TrialLog in
Avatar of sam17
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?
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

show all of the relevant code, as it appears, from what you have shown, that you MIGHT have it written like this:

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
ASKER CERTIFIED SOLUTION
Avatar of Jacamar
Jacamar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sam17
sam17

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?
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.