Solved

Dynamically set properties of a label at run time

Posted on 2007-04-07
5
153 Views
Last Modified: 2013-11-25
Hi,

I have a vb6 projects with numerous forms and numerous labels on the form.  At run time I want to dynamically be able to set the properties of each lablel i.e.  .caption = "XY"

Each label will have a default value for each property that is hardcoded into app, however on a dymanic basis I want to be able to provide a new property value.  Because there are so many labels and forms I don't want to have to programatically put a line in the code for each property.  I simply want a function that I can pass the form to, then the function will change the label properties, by looking up the labels new properties in a SQL table.  I thought you could do it with something similar to the following:

Dim lblDynamicLabel as Object
lblDynamicLabel  = "lblObjectName"
lblDynamicLabel .caption = "GGG"

However this throws an error.

Any ideas?

thanks
0
Comment
Question by:kinton
  • 2
  • 2
5 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 18870021
have a look at the CallByName method
0
 
LVL 2

Author Comment

by:kinton
ID: 18870260
This looks like it calls a method dynamically, how would you use it to update a property where the property and the property value is dynamic?
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 18870302
this way:

Private Sub Command1_Click()
Dim strLabelName As String

    strLabelName = "Label1"
   
    CallByName CallByName(Me, strLabelName, VbGet), "Caption", VbLet, "GGG"
End Sub
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18872632
*** Not for Points ***

Slightly different syntax:

' ------------------
'  Form1
' ------------------
Private Sub Command1_Click()
    SetProp Me, "Label1", "Caption", "GGG"
End Sub

' ------------------
'  Module1
' ------------------
Public Sub SetProp(ByVal frm As Form, ByVal ctlName As String, ByVal ctlProp As String, ByVal ctlValue As Variant)
    On Error Resume Next
    CallByName frm.Controls(ctlName), ctlProp, VbLet, ctlValue
End Sub
0
 
LVL 2

Author Comment

by:kinton
ID: 18875639
Brilliant.  Thank you very mucg for the quick reply,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now