Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving options for applications. Need help!! 1

Status
Not open for further replies.

Tigerman

Programmer
May 15, 2001
18
US
I need to know the best way to develop an "options" form for a program that will enable an application to save changes at runtime for Caption properties. For instance if you had an application with five buttons with the captions: 1. A
2. B
3. C
4. D
5. E

If at runtime I want to be able to change the buttons to say:
1. AA
2. BB
3. CC
4. DD
5. EE

Thus, when the program is closed and reopened, the caption buttons will be changed from Group 1 to Group 2. Obviously there needs to be a file where the changes can be stored and read. What would be the best procedure to follow in order to program the application to have this ability? Out of all the questions I've posted on this forum, this is by far the most significant one I've ever asked. Anyone's help is MUCH appreciated!
 
Search VB Help for SaveSetting and GetSetting.
VCA.gif

Alt255@Vorpalcom.Intranets.com

"Don't be humble. You're not that great."
Golda Meier​
 
In the form load event look for a file, let's assume its name is "captions.dat" in App.Path:

Private Sub Form_Load()
If Dir(App.Path & "\captions.dat") = "" Then
'The file is not present
'so we will create one with defaults
SaveCaptions "A", "B", "C", "D", "E"
LoadCaptions
Else
LoadCaptions
End If
End Sub

As you can see here the idea is to create a caption file with default values the first time the program is run, or any time it cannot find the file. You will need 2 subs, one to write whatever values you want to the file(SaveCaptions), and one to read values from the file and set the captions(LoadCaptions). Here is what those subs would look like.

Private Sub SaveCaptions(ByVal C1 As String, ByVal C2 As String, ByVal C3 As String, ByVal C4 As String, ByVal C5 As String)

Dim FileLine As String

Open App.Path & "\captions.dat" For Output As #1
'print each to one line, makes reading easier
Print #1, C1
Print #1, C2
Print #1, C3
Print #1, C4
Print #1, C5

Close #1

End Sub

Private Sub LoadCaptions()

Dim FileLine As String

Open App.Path & "\captions.dat" For Input As #1

Line Input #1, FileLine
Form1.Label1.Caption = FileLine
Line Input #1, FileLine
Form1.Label2.Caption = FileLine
Line Input #1, FileLine
Form1.Label3.Caption = FileLine
Line Input #1, FileLine
Form1.Label4.Caption = FileLine
Line Input #1, FileLine
Form1.Label5.Caption = FileLine

Close #1

End Sub

To Save New caption values just call SaveCaptions with the desired captions as arguments. Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Hey Ruairi!

Thanks a bunch for taking the time to explain this. This makes the most sense of anything I've read or tried so far. I'll give it a whack next time I'm able to work on my program. Presheadit!

Tigerman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top