
Help saving VB APPS in Win edition
Quote:
> How do I use random access so users can save their program. I want visual
> basic to saves the varabiles and then later when the users want to load a
> program VB loads the varabels into memory. I am a VB beginer using VB 3.0
> for Windows. Standerd edition. Please use understandable terms for a VB
> beginner.
> Example: Varable "HP" is 43 and varable "GP" is 341123.
> User saves and quits the program****
> User loads the program****
> HP and GP are what they were before****
First look at the on line help for the commands Open, Close, Put, Get, Len.
Heres a quick example:
First declale a user defined type(again look that up in the on line
help), that contains the fields you want to save.
Type SavedInfo
HpSaved As Integer 'or what ever type HP is, when using strings make
sure they are FIXED length, ie HpSaved As String*5
GpSaved As Integer
End type
Now on form exit, or where ever it is appropriate
Form_Unload()
Dim RecordLen As Long
Dim Info As SavedInfo
'Calculate the length of each record you store(your user defined type length)
RecordLen = Len(Info)
'get the information to store
Info.HpSaved = HP
Info.GpSaved = GP
'Open the file, note this is a very quick example, you should provide
'code to handle errors..
Open "FileName with Path" for Random As #1 Len = RecordLen
Put #1, RecordNumber, Info
'close the file
Close 'a close with no arguments closes ALL open files.
End Sub
If you combine this with the cmdialog vbx, you can provide an easy way
form multiple users to save their work, form setup....
This way is a bit better then using the ini file. Because you can let
the user save the info to a specific file. Look up the above
mentioned commands and it will seem alot clearer.
----------------------------------------------------------------------
Greg Carter
4th year Electrical Engineering
Carleton University
Take a look at my home page on the
World Wide Web: http://chat.carleton.ca/~gcarter
----------------------------------------------------------------------