-
I want to store some variables within the EXE file itself so that when the program is closed and re-run, the variables will still be remembered.
The variables are from a textbox which asks the user for his name. I want to be able to store it so that it can greet him on his next use.
how do i go abt doing this?
thx
-
<?>
Code:
'
'another opiton is to use SaveSetting and GetSetting
Option Explicit
'
' Variant to hold 2-dimensional array returned by GetSetting.
Dim MySettings As Variant
'to test this out
'make a std project
'add a textbox with "" value for text
'add command1 and command2
'run the app
'click command1
'click the x to unload the project
'reload the project and text1 will now have the text that
'was in it when you quit
'if you want to delete the save settings click on command2
Private Sub Command2_Click()
'this will delete it from the register if you are finished
'with playing with it
DeleteSetting "project1", "TextboxValue"
End Sub
Private Sub Form_Load()
'this will load it into the register
Text1.Text = GetSetting("project1", "TextboxValue", "Value", 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'this will save it into the register when you quit
SaveSetting "project1", "TextboxValue", "Value", Text1.Text
End Sub
Private Sub Command1_Click()
'load the text1.text with whatever
Text1.Text = "Shame on you, you went and did it!"
End Sub
-
thanks, but what do you recommend if i dont want to play around with the registry?
-
I dont want to use the registry because the app will be like a greeting card. You enter a name and then send it off to the receipient.
-
You could try writing the variables in question to an external file, and read them into the program when needed.
-
I tried it but i want to keep the no. of files distributed to the minimum. You know like those messagemates, you can configure it and then it saves into the file itself
-
I think you should use the WritePrivateProfileString and SetPrivateProfileString API calls. With these call you can create an INI file and store info in there.
-
Whether it is an *.ini file or just a normal text file, it looks as if you are going to have to write to as file. A typical text file might be 256 bytes or less. It hardly counts as a file compared to the size of the distributed *.exe.