Solved

How to save a control (not a usercontrol) property at run-time ?

Posted on 2001-08-07
7
225 Views
Last Modified: 2006-11-17
Hi everybody,

I have a label on a form and I would like to be able to change the label caption and to save this caption at run-time.
So the next time I open the project this new caption appears in the property sheet.

Is it possible ?

Thanks

SCML

0
Comment
Question by:scml
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 6360668
No direct way of doing it in a runtime app. Will have to resort to persistent storage such as Registry. But listen to what others have to say, too.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6360727
what "property sheet" are you refering to.  Do you mean the Property Sheet that is displayed in the VB IDE when you either right click on the control, and select Properties, or sselect the control and press the F4 key?

How is your application setup to display the Property Page?
0
 

Author Comment

by:scml
ID: 6360920
Yes, I mean the property sheet that is displayed in the VB IDE. But it would be only to see if the change on the property has been made.

When the program is run, this property sheet will not show of course.

Thanks
0
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.

 
LVL 6

Expert Comment

by:Nitin Sontakke
ID: 6360957
The properties that we change during development, they are persisted in the .frm files itself, which are normal text files, which you can even modify / write even using notepad. IDE is just a tool to create these files, nothing more than that.

At runtime, these files are neighter available nor desired to be present so persisting values in these is just out of question, i think.

You will need to resort to some other storage such as Registry or database, your custome text file, anything...

Runtime modifications to such properties will not again be visible in development environment as obviously they are stored at different places.

Come to think of this, if you are going to supply .frms with app (or may be write to it if file exists!), you can write a function to manipulate these files as they are simple text files. However, i discourage you to do so.

0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6360992
YOu can't change the values of the properties of the control, set when the program is run, to make those changed values visible in the IDE.  However, you can save the values assigned to a control, at run-time, so that the next time the program is run, that (those) controls are set to the values that they were changed to the previous time the program was run.

I do this all the time, using the SaveSetting and GetSetting functins to save/get the values from the System Registry:


Private Sub Form_Load()
  ..
   .
   .
    Evaluator = Val(GetSetting("MissCap", "Assess", "Evaluator", "-1"))
   
    cboEvaluator.ListIndex = Evaluator
    SubFactor = Val(GetSetting("MissCap", "Assess", "SubFactor", "-1"))
    Question = CInt(GetSetting("MissCap", "Assess", "Question", "1"))
    cboSubFactor.ListIndex = SubFactor
    txtQNum.Text = Question
 

here I am retrieving tha values fo the ListIndex property of two ComboBoxes, as set the time before (if not set, then the default value (-1)) is returned (the values are saved in the Registry as Strings, hence the use of the Val function.

then in the event Handler for the cmdDone button which close the app:

    SaveSetting "MissCap", "Assess", "Company", cboCompany.ListIndex
    SaveSetting "MissCap", "Assess", "Evaluator", cboEvaluator.ListIndex
    SaveSetting "MissCap", "Assess", "SubFactor", cboSubFactor.ListIndex
    SaveSetting "MissCap", "Assess", "Question", txtQNum.Text
  I save the current setting of the Control values, so they can be restored the nexct time the program is run.


Look up the SaveSetting and GetSetting functions in the VB Help System.
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 100 total points
ID: 6361000
YOu can't change the values of the properties of the control, set when the program is run, to make those changed values visible in the IDE.  However, you can save the values assigned to a control, at run-time, so that the next time the program is run, that (those) controls are set to the values that they were changed to the previous time the program was run.

I do this all the time, using the SaveSetting and GetSetting functins to save/get the values from the System Registry:


Private Sub Form_Load()
  ..
   .
   .
    Evaluator = Val(GetSetting("MissCap", "Assess", "Evaluator", "-1"))
   
    cboEvaluator.ListIndex = Evaluator
    SubFactor = Val(GetSetting("MissCap", "Assess", "SubFactor", "-1"))
    Question = CInt(GetSetting("MissCap", "Assess", "Question", "1"))
    cboSubFactor.ListIndex = SubFactor
    txtQNum.Text = Question
 

here I am retrieving tha values fo the ListIndex property of two ComboBoxes, as set the time before (if not set, then the default value (-1)) is returned (the values are saved in the Registry as Strings, hence the use of the Val function.

then in the event Handler for the cmdDone button which close the app:

    SaveSetting "MissCap", "Assess", "Company", cboCompany.ListIndex
    SaveSetting "MissCap", "Assess", "Evaluator", cboEvaluator.ListIndex
    SaveSetting "MissCap", "Assess", "SubFactor", cboSubFactor.ListIndex
    SaveSetting "MissCap", "Assess", "Question", txtQNum.Text
  I save the current setting of the Control values, so they can be restored the nexct time the program is run.


Look up the SaveSetting and GetSetting functions in the VB Help System.
0
 

Author Comment

by:scml
ID: 6361387
Thanks to all !

SCML
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

Suggested Solutions

Title # Comments Views Activity
VB 6.0 printer how to align 6 58
Validating VB6 Function 19 56
Notepad++ how to remove delimiter : from beggning of the line? 3 94
Hide vba in gp 7 83
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

863 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

28 Experts available now in Live!

Get 1:1 Help Now