?
Solved

VB: label

Posted on 2003-03-24
4
Medium Priority
?
206 Views
Last Modified: 2011-10-03


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?
0
Comment
Question by:sam17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8196742
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
0
 
LVL 2

Accepted Solution

by:
Jacamar earned 1000 total points
ID: 8196871
One thing that simplifies programming is to use variables to hold your values.  It becomes easier to keep track of, and you are less likely to have errors.

dim sgNetCharge as single

'set values to DAYCHARGE, NumberOfDays, ect

sgNetCharge = (DAYCHARGE * NumberOfDays) + (MILESDRIVENCHARGE * MilesDriven)

lblNetCharge.Caption = sgNetCharge
0
 

Author Comment

by:sam17
ID: 8197509
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?
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8197737
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.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Simple Linear Regression
Progress
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question