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!

"Save" Function

Status
Not open for further replies.

huBBLe

Programmer
May 15, 2001
50
SG
i'm writing a financial planning application which allow users to input quite a number of figures and the application will calculate the relevant values. i used textboxes to accept user input.

now, i would like to be able to allow the user to save the contents of the application. was thinking of writing all values from the textboxes to a .txt file, line by line, when saving. and when loading the file back, will put the vlues back into their respective textboxes.

is this a good way of doing things (sounds pretty dumb), or is their an easier way?

can i save the application as a whole instead of by values?
 
Hi,

Saving the valus into a text file (usually .ini in the temporary directory) is one way of doing it.
Another is to use the getsetting and setsetting function to save the values in the windows registry. Look up the help reference for these functions. Let me know if you need more help.

Sunaj
 
Hi sunaj,

I went to read up on these 2 functions, and even downloaded some codes on reading and writing to registry. i have a few questions:

1. It seems to me that the file format that the settings are saved in is .INI. Is this the only option? I saw some codes that write to the registry itself, what are the differencees, advantages and disadvantages of these two ways?

2. Let's say I want to be able to save multiple files, would it still be possible (if i were to use the .ini way)?

3. I'm thinking of using a common dialog box for directory access, do u think it's a good idea?

I'm juz a newbie in VB, so please pardon me if the questions seem dumb.

Thanks for replying
 
It looks like .INI but SaveSettings writes to the registry under HKEY_CURRENT_USER / SOFTWARE / VB and VBA PROGRAM SETTINGS / your application key. The nice thing about an .INI located in your application directory is that it is portable and can be backed up independent of the registry. You can store multiple .INIs because filename is part of the call.
 
Do you think that your process could be easier if you stored your data in a database such as Microsoft Access instead of a text file, or was there a reason for wanting to use a text file?
 
Thanks to all who replied.

A few more questions:

1. Are saving as .ini and writing to the registry the only two ways to save data in an application? Any other methods worth trying?

2. What exactly is an .ini file? Can someone care to tell me what this file format is for?

3. I have multiple textfelds, combo boxes and option boxes (numbering at least 50 total) and what i did was to call the win32 API function every single time for each value, which seems very inefficient. Any idea how i can load a group of data with juz one call?

To antwar420:

No. There is no significance in writing to a .txt file. Its was juz an idea before I got to Know the two other methods as a .txt file seems easy to operate on. As to your suggestion to write to Access, wouldn't it be a tad more troublesome than the two ways?
 
VB has made it easy to connect to databases, I would recommend you use an access db. I'm a student, and we have an assignment on exactly this! I'm finding it pretty easy to do. if you want, VB6 has a new control called ADO which makes it pretty easy.
I've never tried the writing to registry or ini, but you could also try them.
The good things about ini files and databases is that they are portable. Easy to back up aswell.
But make up your own mind.
 
Hi leewaich,

1&2. Usually, people can save data in three media:
-. A Database (Access, SQL Server, etc..)
-. A Text file (.ini, .txt)
-. Registry

.ini (initialized file) just like its name is used to store application setting like screen height/width, last field value entry by user, etc. One of the purpose of .ini file is to set the app so when it is loaded, it will be the same as when it opened last time. Notice that an .ini file is limited to 64KB.

Registry is used to store any app setting that needs a more high security level. If your app has a vital information setting which is required to launch the application, put it on registry.

Not like an .ini file which is easy to modify, editing registry without crashing any program installed needs an advanced skill. This can prevent user form 'harming' your application.

Save your data in a database, save your app setting in an .ini file or registry.

Good luck;-)
 
Hi

If you have named your controls consistently, you can do something like:

------------------------------------------------------------
for each vnt in MyForm
select case left(vnt.name,3)
case "Txt", "Opt": savesetting MyApp,VbNullChar,vnt.name, vnt
case "Cmb":
for i=0 to vnt.listcount-1
tmp=vnt.list(i) & ", "
next i
tmp=left(tmp,len(tmp)-2)
savesetting MyApp, VbNullChar, vnt.name, tmp 'Use spilt to read the values as an array
end select
next vnt
------------------------------------------------------------

The code for saving in an .ini file would be almost the same, just use print# instead of savesetting.

:) Sunaj
 
leewaich,

I'm developing a program using procedures nearly identical to the one you mentioned on the above strings. I need to be able to save text from the textboxes so they can be recalled again when the user reopens the program. Have you found a solution to your question? If so, do you mind sharing with me which route you decided to take?

Thanks!

Tigerman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top