[Gambas-user] Saving & Loading multible Variables

nando nando_f at ...951...
Tue Jan 10 20:10:45 CET 2006


Here's how I do multiple variables into 1 file (v 1.0.6)


DIM i AS INTEGER
DIM s AS STRING
DIM q as SHORT
DIM hfile AS FILE

OPEN "/home/folder1/my_vars/" FOR WRITE AS #hfile
WRITE #hfile, i
WRITE #hfile, s, 3
WRITE #hfile, q
CLOSE hfile


............

The 9 byte data file is of the following format:

Offset +0 +1 +2 +3 --> contains a 4 byte integer
Offset +4 +5 +6    --> contains 3 bytes corresponding to 's' 3 chars long
Offset +7 +8       --> contains a 2 byte integer


-Fernando



---------- Original Message -----------
From: Muriel Bodard <abidoo.too at ...11...>
To: gambas-user at lists.sourceforge.net
Sent: Tue, 10 Jan 2006 18:44:27 +0100
Subject: Re: [Gambas-user] Saving & Loading multible Variables

> Le Lundi 09 Janvier 2006 19:12, Scott a écrit :
> > Hi again,
> >
> >     I found a walk around my problem with saving and loading multiple
> > variables.  It is simple to save and load a single variable, so I simply
> > saved each variable to a different file.  It is a little messy, but it
> > works; and in the end that is what really matters :)  If anyone can
> > still tell me how to save multiple variables into a single file, that
> > would be nice.
> >
> >     I have placed the code down I used in a test program that works just
> > in case other people are having the same problem and don't mind my quick
> > fix to this problem.  I even added a bit in to save the files to a
> > specific folder and to create that folder if it does not exist.
> >
> > PUBLIC SUB Save_Click()
> >
> > DIM a AS String
> > DIM b AS String
> > DIM c AS String
> > DIM d AS String
> > DIM fe AS Boolean
> >
> > fe = Exist ( system.Home &/"savetest" )
> > IF fe = FALSE THEN MKDIR system.Home &/"savetest"
> >
> > a = textbox1.Text
> > b = textbox2.Text
> > c = textbox3.Text
> > d = textbox4.Text
> >
> > File.Save(system.Home &/"savetest/testa.txt", a)
> > File.Save(system.Home &/"savetest/testb.txt", b)
> > File.Save(system.Home &/"savetest/testc.txt", c)
> > File.Save(system.Home &/"savetest/testd.txt", d)
> >
> > END
> >
> > PUBLIC SUB Load_Click()
> >
> > DIM a AS String
> > DIM b AS String
> > DIM c AS String
> > DIM d AS String
> >
> > a = File.Load(system.Home &/"savetest/testa.txt")
> > b = File.Load(system.Home &/"savetest/testb.txt")
> > c = File.Load(system.Home &/"savetest/testc.txt")
> > d = File.Load(system.Home &/"savetest/testd.txt")
> >
> > textbox5.Text = a
> > textbox6.Text = b
> > textbox7.Text = c
> > textbox8.Text = d
> >
> > END
> 
> ARRRRRGH !
> 
> 8°O  What is that ?
> 
> Look :
> Private arsValues as String[]
> 
> Public sub Main()
>   Dim s as string
> 
>   arsValue = New String[]
> 
>   arsValue.Add("Val1")
>   arsValue.Add("Val2")
>   arsValue.Add("Val3")
>   arsValue.Add("Val4")
> 
>   Save
> 
>   arsValue.Clear
> 
>   Load
> 
>     For each s in arsValue
>       Print s
>     Next
> 
> End
> 
> Public Sub Save()
>   File.Save(system.Home &/"savetest/testd.txt", arsValue.Join("\n"))
> End
> 
> Public Sub Load()
>   arsValue =Split( File.Load(system.Home &/"savetest/testd.txt"), "\n")
> End
> 
> Never The less gambas have a setting system
> 
> Use it !
> 
> Private MySetting as Setting
> 
> in a sub...
> 
> MySetting = New Setting(system.Home &/"savetest/testd.txt")
> 
> Setting["Val1"] = Val1
> Setting["Val2"] = Val2
> etc...
> Setting.Save
> 
> To LoadSetting:
> 
> Val1 = Setting["Val1"]
> etc
> 
> to remove a setting if i remember good...
> 
> Setting["Val1"] = Null
> 
> Regards,
> Fabien Bodard
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log 
> files for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> [UTF-8?]http://ads.osdn.com/?ad_idv37&alloc_id865&opÌk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list