Solved

Save Feature

Posted on 2003-11-06
8
290 Views
Last Modified: 2010-05-03
I have a stand-alone EXE, and this EXE has 3 variables that are used for some complex calculations. I have made it so that these variables can be changed if need be, but when the exe is re-opened those numbers must be changed again. Is there a way for me to change those variables once, save it, and not have to correct them again (unless they actually need to change.

The variables right now are 68, 63, & 9. Later, they may need to be changed to 70, 65, & 15. And even further down the road, they may need to be changed again. I just don't want to have to code and re-compile unless necessary. Thanks!
0
Comment
Question by:JFrye
[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
  • 2
  • +2
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9696071
The fastest way would be to pass them in as parameters to your application and then create a shortcut.

app.exe 68 63 9

Then in your code you can retrieve the items using the command function.

Private Sub Form_Load()
    Dim parameters As Variant
    parameters = Split(Command())
   
    Dim a As Integer
    For a = LBound(parameters) To UBound(parameters)
        Debug.Print "Parameter " & a; " = " & parameters(a)
    Next a
End Sub

Or you could save those values in the registry and provide some way in app to update them.

Private Sub Form_Load()
    SaveSetting "MyApp", "Variables", "Value1", 68
    SaveSetting "MyApp", "Variables", "Value2", 63
    SaveSetting "MyApp", "Variables", "Value3", 9

    Dim a As Integer, b As Integer, c As Integer

    a = GetSetting("MyApp", "Variables", "Value1")
    b = GetSetting("MyApp", "Variables", "Value2")
    c = GetSetting("MyApp", "Variables", "Value3")
   
    Debug.Print a, b, c
End Sub
0
 
LVL 1

Expert Comment

by:lampy24
ID: 9696087
Why not save those values to a  config file or the registry!  Which will persist the values from each opening of the exe.  So, the values can be changed from without a recompile.  For your app I suggest using a config file and everytime the app is launched you just open the file and read in the values and when you want to change the values just rebuild the file with the values.

Good Luck
0
 

Author Comment

by:JFrye
ID: 9696121
Well, I'd rather not have any registry entries or extra files. This app is actually located on a corporate network, and all PCs have the registry locked. That's why I need just one file - the app itself. If it isn't possible, that's fine. Just let me know if it absolutely isn't possible to do it the way I prefer. Thanks!
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 1

Accepted Solution

by:
lampy24 earned 30 total points
ID: 9696135
Here is link for a guide for either config (ini) file or using the registry:

http://www.thescarms.com/vbasic/registry.asp
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9696143
Use my first suggestion then and pass them in as parameters.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 9696367
you asked "Is there a way for me to change those variables once, save it, and not have to correct them again (unless they actually need to change)", and yet you then say "I'd rather not have any registry entries or extra files".

Where would you want to SAVE the values if not in an 'extra file'?

The values MUST be saved somewhere, and the Registry or en External file are the only choices.

AW
0
 

Expert Comment

by:gr8white
ID: 9696554
I think you'll find that even though the registry is "locked" your app will still be able to create the entries.  THe SaveSettings command in VB writes only to a special key in the registry and can't screw up anything other than your app (for that you need to use API calls!)

Obviously the other apps running on your network PCs need to be able to store their settings in the registry.

Ken
0
 

Author Comment

by:JFrye
ID: 9696709
I wanted to be able to just alter the app itself without re-coding and re-compiling. But after a little thought, it isn't really that big of a deal compared to a config file.

A registry entry is out of the question since multiple PCs will use this app, and I can't change everyone's registry.

So, I'll take lmapy's answer. Thanks, everyone!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

696 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