Solved

Dynamically set properties of a label at run time

Posted on 2007-04-07
5
160 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

615 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