Solved

Dynamically set properties of a label at run time

Posted on 2007-04-07
5
159 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
[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
  • 2
5 Comments
 
LVL 70

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 70

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 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro: print each sheet to pdf using ExportAsFixedFormat 11 71
Child Form in front 4 66
VB6 ListBox Question 4 63
Remove Exif Orientation before adding image to db 9 63
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 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