Label format

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Hi all, I need to format multiple labels with the same format, basically a 2 place decimal, 0.00. what would be the easiest way be to achieve this, and where do I construct it - property or sub routine? I am not very good at setting properties yet...

Much confusion after searching for hours...
 
Ok, form opens, user selects an option in a list box, I have two textboxes for entering numbers, I am using 'select case' for the equation based on which index they select, the calculation(using the numbers in the textboxes) happens and the value of that calculation is sent to label(s) (i.e. the answer(s)) so like a calculator but very specific, and these labels(yes more than one) change based on the diff. indexes selected. Hope the is enough info now, thanks for all the hard work so far, lots of fun so far...

PS I have purchased VB.Net the beginners guide, any ideas for books concerning controls, arrays, datagrid, data binding, etc... so far just form stuff not into web stuff yet.
 
Sounds to me like the thing to do newguy would be to just format the data how you want it at the time that "value of that calculation is sent to label(s)". I believe Juggalo or John mentioned this earlier in the thread, and you had an example that was working.

It may not be the most efficent but it's sutiable for learning and progression.

As for reccomened books and etc, the Books - Suggested Reading forum here has a few suggstions, but I've always found that tinkering around and then posting my question in a community like this was the best way to learn.
 
That's correct and it will work, like you said I like to learn by doing, and I look for more challenging things to build. Thanks Again...
 
Did you try a function?

... the other thing I just came across that fixes my initial issue -
label1.text = format(Cdbl(textbox1.text) * Cdbl(textbox2.text), "f") and I have to use it on every line - which will work, but am wondering if there is a short cut like a constant or property that may shorten the load in the long run, plus I learn from doing new and different things ...

Did you try a function? Something like:

VB.NET:
Public Function FormatMyLabels ( _
  ByVal label As System.Windows.Forms.Label, _
  ByVal txt1 As System.Windows.Forms.Textbox, _
  ByVal txt2 As System.Windows.Forms.Textbox)
    label.text = format(Cdbl(txt1.Text) * Cdbl(txt2.Text), "f") 
    Return label.Text
End Function

Now I really don't know what ' " f " ' is, but you could announce it after the ByVals
 
Last edited:
Back
Top