In this tutorial we will learn how can we save and load data from Listbox Control available in REALbasic. I hope you will like this tutorial and you will enjoy it!
Drag and drop to Window1 a Listbox Control and add to it two columns named Software and Description. Now add there some data. If you have a problem with this you can simply select the Listbox Control and in Property InitialValue enter there some text. To get to next row press enter, to get to next column press Tab key from keyboard.
Create a New Method and name it ListboxSave
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Dim f As FolderItem Dim t As TextOutputStream Dim i As Integer Dim l As String f = SpecialFolder.Preferences.Child("ListboxData") if f < > nil then // f different from nil t = f.CreateTextFile if t < > nil then // t different from nil for i = 0 to ListBox1.ListCount -1 l = ListBox1.Cell(i,0) + chr(9) + ListBox1.Cell(i,1) t.WriteLine l next t.close end if end if |
Create a New Method and name it ListboxLoad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Dim f As FolderItem Dim t As TextInputStream Dim l As String f = SpecialFolder.Preferences.Child("ListboxData") if f < > nil then // f different from nil if f.exists then t = f.OpenAsTextFile if t < > nil then // t different from nil ListBox1.DeleteAllRows //clear items from Listbox do l = t.ReadLine //l is made up of the software name + tab character chr(9) + the descrition ListBox1.Addrow nthField(l,chr(9),1) //the first field of l is Software ListBox1.Cell(ListBox1.LastIndex,1) = nthField(l,chr(9),2) //the second field of l is Description loop until t.EOF //keep looping until the End Of the File t.close end if end if end if |
To load and save data when our software is starting and closing go to code editor and in Event Handlers Sub Open () enter ListboxLoad and in Event Handlers Sub Close () enter ListboxSave.
Superb information!
This is great, Though How do I take the data from a list box and add it to a table
example : I have listbox1 and a table called “table1″
I want the user to type in the information in to the listbox1 (single column) and then press a button to save that information to a table.
I know this is simple but I am very new to programming
thanks
Cory
I don’t understand what you like to get Cory…
I do not understand this statement
f = SpecialFolder.Preferences.Child (“ListboxData”)
Not find an explanation in the Language Reference
massimo if you are using Windows or Linux you can for example enter: f = SpecialFolder.Desktop.Child(“ListboxData”) //the file will be saved and load from the system desktop