Solved

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

Posted on 2001-08-07
7
234 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

803 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