English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have yet another question about Visual Basic 6. I need to know the coding for saving what is inputed into a form at run-time by a user and loading it back up when it is run again.

Basically...I need it to save what the user puts into the program...

if you need a screenshot of what I am doing, e-mail me, I can't download pictures in this room.

2006-11-03 03:49:49 · 6 answers · asked by Lottare 2 in Computers & Internet Programming & Design

6 answers

You can do this many ways.
I will show you how to do it using the registry and a simple text file.

1) I assume you have a control on your form that is supposed to save the data when it is clicked, double clicked or whatever.

2) The "save" code will go in the appropriate event (click/double click/mouse over/whatever), the "load" code will go in either the form load event or the "Sub Main" of your startup object. According to your description you want the data to "auto load" when the application is started.

SAVE CODE Example 1:
SaveSetting applicationname, "Settings", "Last Name", txtLastName.Text
SaveSetting applicationname, "Settings", "First Name", txtFirstName.Text
SaveSetting applicationname, "Settings", "Address", txtAddress.Text
SaveSetting applicationname, "Settings", "City", txtCity.Text
SaveSetting applicationname, "Settings", "State", txtState.Text
SaveSetting applicationname, "Settings", "Zip", txtZip.Text

applicationname is the name of your application (duh)
"Settings" is a literal that can be anything meaningful that you want...such as;"Form1 Settings", "Address Settings", etc
The next parameter ("First Name","Last Name", etc.) is a meaningful name for each "thing" you want to save.
The last parameter is the actual data that you are wanting to save.

SAVE CODE Example 2:
dim intFileNum as integer
intFileNum = FreeFile
Open "Settings.txt" for output as #intFileNum
print #intfilenum, txtLastName.Text
print #intfilenum, txtFirstName.Text
print #intfilenum, txtAddress.Text
print #intfilenum, txtCity.Text
print #intfilenum, txtState.Text
print #intfilenum, txtZip.Text
Close #intFileNum

The above code open a text file on your default drive and in a default location, generally where you have saved your application.
It then writes data to this file one line at a time, no identifiers or anything, just data followed by carriage return and line feed (vbCRLF).
The last line flushes the write buffer and closes the file.


READ CODE Example 1:
txtLastName.Text = GetSetting(applicationname, "Settings", "Last Name", "")
txtFirstName.Text = GetSetting(applicationname, "Settings", "First Name", "")
txtAddress.Text = GetSetting(applicationname, "Settings", "Address", "")
txtCity.Text = GetSetting(applicationname, "Settings", "City", "")
txtState.Text = GetSetting(applicationname, "Settings", "State", "")
txtZip.Text = GetSetting(applicationname, "Settings", "Zip", "")

This is just the reverse of the SaveSetting, however, the last parameter ("") is a default is the setting cannot be found in the registry.


READ CODE Example 2:
dim intFileNum as integer
intFileNum = FreeFile
Open "Settings.txt" for input as #intFileNum
input #intfilenum, txtLastName.Text
input #intfilenum, txtFirstName.Text
input #intfilenum, txtAddress.Text
input #intfilenum, txtCity.Text
input #intfilenum, txtState.Text
input #intfilenum, txtZip.Text
Close #intFileNum

2006-11-03 06:26:04 · answer #1 · answered by timc_fla 5 · 0 0

Suppose you want to save a name that an user inputs. Then you can try the following
name a variable ex. 'a' then code a=text1.text
text1 is the name of the text box where the user inputs. If you have a database then save all those info there. You need separate coding for database connectivity. Then when you need to show the input later on you can retrieve the info from database and show.
If you need to save the info in the program then name different user inputs by different variable and save them.

2006-11-03 04:29:59 · answer #2 · answered by star_unknown1 3 · 0 0

This is the dumbest question I have seen on Yahoo!

You have to simply save them into Database and its such a simple part of a software development life cycle!!!

But since u asked, I hope its more complicated than you have explained. Add a comment of how big of a thing is your problem. If its just showing some start up fields, then we do it daily basis in Web Development.

Good Luck!

2006-11-03 06:01:42 · answer #3 · answered by KS 3 · 0 1

You need to save the 'settings' either to the registry, database or an text file. And then on reload read the 'settings' that were saved.

See the following article on some easy ways to access the registry from VB : http://www.freevbcode.com/ShowCode.Asp?ID=607

2006-11-03 04:09:37 · answer #4 · answered by Special Ed 5 · 0 0

you can do this different ways. Maybe use a database and bind all the text fields to the columns in the database this is the easiest. save to a text file or some sort of dat file and just read it in. use

2006-11-03 04:52:34 · answer #5 · answered by Anonymous · 0 0

i can n't under what do u want

2006-11-03 04:03:52 · answer #6 · answered by Anonymous · 0 2

fedest.com, questions and answers