Making a Combo Box Read/Write With A File?

So I just started using Xojo and my first project I wanted to try for learning the program was something for my dad. He asked me a while back if there was something he could have and use that had his most frequently used websites in one place instead of digging through all of their bookmarks and such, he could just access the sites from his own thing. So i figured a small application would do the job just fine. I haven’t had a problem until I got to reading and writing to a file for the application to save inputted data. I have no idea how to make the combo box pull up a list of websites from a file, or how to write any added files in the application to the same file to save it for the next startup.

(Side note: I’m making the application on windows, but he uses an iMac. is the coding different between the platforms?)

I would suggest saving the data into an SQLite database.
http://developer.xojo.com/userguide/sqlite
Example Projects > Database > SQLite > SQLiteExample.xojo_binary_project

This would make it very easy to read and write data :slight_smile:

The coding: more or less the same.

The application: cannot run on the other platform.

Nota: a simple text file with html as extension is enough, no need for a 4 MB application. And this is cross platform.
Ask if you need hints…

@Emile Schwarz so instead of a SQL database, write an HTML to read from? How would that be written?

To write your file, see http://documentation.xojo.com/index.php/TextOutputStream
The third example is usually easy to use.

To read the file you have created, see http://documentation.xojo.com/index.php/TextinputStream

I may be wrong, but doing an application to keep links (URLs like bookmarks) while a simple text file (html) with the links is enough.

The file will hold all links as:

Xojo Download

etc.

Did I correctly understand what you want to do ?

I’ve tried this code for what I’m trying to do and it’s set to an event for the combo box. I don’t know if that’s the right way to do it or not, but it’s what I’ve got.

Dim line1, line2 As String Dim f As FolderItem = SpecialFolder.UserHome.Child("List.txt") // your file location If f <> Nil Then If f.Exists Then Dim t As TextInputStream Try t = TextInputStream.Open(f) t.Encoding = Encodings.UTF8 line1 = t.ReadLine line2 = t.ReadLine Catch e As IOException t.Close MsgBox("Error accessing file.") End Try End If End If
I want the combo box to load a list of items I can choose from, but getting it to load the list in lines to select has been the challenging part…

is the code in Open Event ?

Where do you .AddRow the loaded Text ?

it is in Open. is that wrong? Like i stated before i’m new to all of this lol

The Open event is appropriate. In it, call the ComboBox.AddRow method for each line you want to add.

t = TextInputStream.Open(f) t.Encoding = Encodings.UTF8 //line1 = t.ReadLine //line2 = t.ReadLine Do Until t.EOF Me.AddRow(t.ReadLine) Loop

Answer ?

Thanks, @Andrew Lambert I can get this working!

@Emile Schwarz I just saw and understood your question. That’s part of what I was missing. I had no way to get it read lines into a row.