[Gambas-user] Saving & Loading multible Variables
Muriel Bodard
abidoo.too at ...11...
Tue Jan 10 18:44:27 CET 2006
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
More information about the User
mailing list