Solved

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

Posted on 2001-08-07
7
213 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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