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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label Variable

Status
Not open for further replies.

Jefftopia

Programmer
Jul 30, 2002
104
US
I am attempting to change the caption property of a label on one form from the code in a different form. Easy enough except the name of the label (whose caption property I am trying to change) must be dynamic.

Why won't this work?

Dim MyLabel As Label

Form2.MyLabel.Caption = "something"


After I type "Form2." I am not given MyLabel as a choice. This where the problem starts.
 
You will not be given the option of the label name if it is dynamic as the IDE does not know the label (it does not exist at design time). You could just make the label on the form2 and set its visible property to false at design time then during runtime make it visible. That would be the easiest way. Is there a reason you can't do that? If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
You could do this:

Dim LabelName As String

LabelName = "Label1"
Form2.Controls(LabelName).Caption = "This is Label1"

LabelName = "Label2"
Form2.Controls(LabelName).Caption = "This is Label2"
 
thanks bjd4jc,

i am using your method successfully:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top