Best thing to do is save the edittext 'text' to a map using the edittext name as the key then save the map to file. On load it is a simple matter to loop thru the map and load the edittext.
Sub Globals
Dim sets As Map
sets.Initialize
End Sub
Sub savebtns
sets.Clear
sets.Put("EditText1", EditText1.Text)
sets.Put("EditText2", EditText2.Text)
File.WriteMap(File.DirInternal, "btnset.set", sets)
End Sub
Sub loadbtns
sets = File.ReadMap(File.DirInternal, "btnset.set")
EditText1.Text = sets.Get("EditText1")
EditText2.Text = sets.Get("EditText2")
End Sub
Something like this should work for you. Be sure to change all the EditText names to whatever you like.
B4X:Sub Globals Dim sets As Map sets.Initialize End Sub Sub savebtns sets.Clear sets.Put("EditText1", EditText1.Text) sets.Put("EditText2", EditText2.Text) File.WriteMap(File.DirInternal, "btnset.set", sets) End Sub Sub loadbtns sets = File.ReadMap(File.DirInternal, "btnset.set") EditText1.Text = sets.Get("EditText1") EditText2.Text = sets.Get("EditText2") End Sub
By the way, does the "load& save code" offer to load & save actual file names? When loading, does the user see a list of files to load? Thanks in advance, as always.
Marsh
What you need is the dialogs library http://www.b4x.com/forum/additional-libraries-official-updates/6776-dialogs-library.html one of the dialogs in the example has a very good example of a file dialog which should be exactly what you need. Not sure about the others but I taught myself VB.net and this is very similar, I am a big fan of trying out all sorts of different options and downloading example programs and working thru them, nothing like getting your hands dirty.
Sub btnSave_Click
Dim fd As FileDialog
Dim ret As Int
fd.FastScroll = True
fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string
fd.ChosenName = "btnset"
ret = fd.Show("Please Enter File Name" & CRLF & "And Select Save Location", "Save", "Cancel", "",Null)
If ret = -1 Then
sets.Clear
sets.Put("EditText1", EditText1.Text)
sets.Put("EditText2", EditText2.Text)
File.WriteMap(fd.FilePath, fd.ChosenName & ".set", sets)
End If
End Sub
Sub btnLoad_Click
Dim fd As FileDialog
Dim ret As Int
fd.FastScroll = True
fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string
fd.ChosenName = "btnset"
fd.FileFilter = ".set"
ret = fd.Show("Please Select File", "Load", "Cancel", "",Null)
If ret = -1 Then
sets = File.ReadMap(fd.FilePath, fd.ChosenName)
EditText1.Text = sets.Get("EditText1")
EditText2.Text = sets.Get("EditText2")
End If
End Sub
label1.text = fd.ChosenName
Just a short example of a save and load sub
in my activity I have 2 edittexts and a save and load button, when you click save it brings up the first dialog select where you want to save, enter a name then click save. Then if you either clear the edittext, rerun the app or rotate the screen then click load and find the saved file. There is no error trapping in the code it is just an idea of what can be done.B4X:Sub btnSave_Click Dim fd As FileDialog Dim ret As Int fd.FastScroll = True fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string fd.ChosenName = "btnset" ret = fd.Show("Please Enter File Name" & CRLF & "And Select Save Location", "Save", "Cancel", "",Null) If ret = -1 Then sets.Clear sets.Put("EditText1", EditText1.Text) sets.Put("EditText2", EditText2.Text) File.WriteMap(fd.FilePath, fd.ChosenName & ".set", sets) End If End Sub Sub btnLoad_Click Dim fd As FileDialog Dim ret As Int fd.FastScroll = True fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string fd.ChosenName = "btnset" fd.FileFilter = ".set" ret = fd.Show("Please Select File", "Load", "Cancel", "",Null) If ret = -1 Then sets = File.ReadMap(fd.FilePath, fd.ChosenName) EditText1.Text = sets.Get("EditText1") EditText2.Text = sets.Get("EditText2") End If End Sub
Dim NewFile As String
NewFile = fd.ChosenName
NewFile = NewFile.Replace(Chr(10), "")
I don't understand exactly what you mean with this.I'd need to use a file dialog box to save and load the contents of multiple labels with a single click under one filename without a line return/line break
Probably nobody had the idea to put a line feed in a file name.I'm very surprised that this hasn't been mentioned before?
I agree with you that the FileDialog shouldn't allow a carriage return.
But as a workaround you can use the code in my previous post that removes any carriage return character.
Probably nobody had the idea to put a carriage return in a file name.
Best regards.
You define a string variable holding the file name, and this lineremoves the line feeds.B4X:NewFile = NewFile.Replace(Chr(10), "")
Best regards.