Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change label text during run-time? 1

Status
Not open for further replies.

combs

Programmer
Apr 18, 2002
78
US
I have a form that has several combo boxes and text boxes. Based on the value of one of the combo boxes, I'd like to enable/disable some of the text boxes AND change the corresponding label of the text box.

The Problem: When I try to write the code for that, VB [2008] will not recognize the label... It doesn't appear in the drop-down "inteli-sense", and if I just write it in and try to de-bug, it errors on that line...

Here's the code:
(The label is named lblLength)
Code:
Select Case m_Units
   Case "EA"
       [COLOR=red]'Me.lblLength.Text = "Count: "[/color]   [COLOR=green]<--- error causing line[/color]
   Case "SF"
   Case "LF"
   Case "SY"
   Case "CY"
   Case "CF"
   Case "OTH"
End Select

This select statement is inside this Sub:
Private Sub WorkItemComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WorkItemComboBox.SelectedIndexChanged


Is there some reason why this I'm unable to access the label text??
 
The only way I could that behavior happening is if you added the label in code instead of the designer. In that case, if the variable for the label is out of scope, you can refer to it by name--if you've set the name--within the Controls collection of it's container. For example:
Code:
CType(Me.Controls("lblLength"), Label).Text = "Count:  "
 
RiverGuy,

Thanks for your reply. Unless I'm doing something wrong (and the probability of that is high), it's still not working.

What I don't understand is this: How come I can code other controls to change their value during runtime, but I can't change the text of a label??

Here's what I'm trying to do.... I have an inventory entry page where measurements of construction items are entered. Some are measured in square feet or yards and others are single measurements like "Each" (i.e. Remove Tree)

When I encounter the inventory item whose unit is "Each", I'd like to do a couple of things....
1. Change the Length text box label (lblLength) to read "Count: " and
2. Disable the Width text box since there is no width measurement required for a single item.

I can disable the width text box already, it's just the text of the label that's giving me the problem....

I've attached a screenshot of the inventory entry form in case that helps in some way...

Thanks for your help!
 
 http://bil.ci.billings.mt.us/pwe/employee/ROWPermits/images/form.jpg
You should be able to. I'd try deleting lblLength, and dragging a new label onto your form, calling it lblLength.
 
RiverGuy,

Thanks for your continued help....
I failed to mention that these controls are on a tabpage. Does that matter?
What is the correct syntax to access a label on a tab page?

This still doesn't make sense because I can access the other controls (combobox or text box) and I can't even SEE the labels....

Help! I'm confused.

I tried what you suggested to no avail... Even tried adding a completely new label (for something unrelated) and was still not able to access it.
 
CLARIFICATION: By "SEE", I mean in the 'inteli-sense' drop down box during coding...

Thanks
 
combs,

Did you set the GenerateMember property of the label to True, this property is set to true when you drag a label to your form from the toolbox. If the label is generated automatically when you drag an object from the DataSource it will be set to False and you will get this kind of behavior.

Perrin
 
May be silly I am ..
Are you sure your label actually named "lblLength" not its caption?

Zameer Abdulla
 
Combs,
You should be able to simply refer to the label by name. i.e. me.label1.text ="whatever"

Sounds like your not looking for the right label OR you've mispelled the name of the label.
 
kliot,

That was the problem. I don't know why it was that way, but you nailed it on that suggestion.

A star for your help!

Thanks to all who contributed.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top