I just started out with Xojo and are playing around with the design part mostly till now, but I am halfway through the Introduction to Programming with Xojo PDF file. What I don’t understand is how I can add a save option to my project. In my current project (the main reason I am studying Xojo) I will have mostly text fields that later on need to be printed, but of course the project file itself has to be saved as well. How do I add this?
Depending on the type of data, you could save the data to a text file using TextOutputStream.
How much data do you have? Does the data have a structure? Is it always same or similar data?
Check out json (http://documentation.xojo.com/index.php/JSONItem), which can be used as a simple format for your data. Then define a file type and save/load your data with the TextOutputStream.
My data is only text data. The only thing that the program will do is filling in text fields. Later on I also want to print all the text that the user filled into these text fields to a a printer or export as PDF.
The example project at
Example Projects/Files/BinaryStream/BinaryStream.xojo_binary_project will get you started on reading and writing files. You can use one of many methods to store data, just be sure you write it in a way you can fetch it back later
Additionally, for much larger amounts of data you can use a SQLite database.
Thanks Tim! I will have a look. I am a little confused with the terminology; writing and reading a file means saving and opening a file? (Still a very beginner in programming here…)
Before you can either write or read a file it needs to be opened. Writing a file is saving it.
Try to write something like
"Textfield1:" + Textfield1.value
as first step. After reading the data back in use nthfield to get your value back. Then experiment how to get this working for multiple fields.
The best doc about TextOutPutStream is http://documentation.xojo.com/index.php/Textoutputstream
The third example at that page is real simple, but contains all the basics to write whatever you need.
If you have several fields, you may want to use a format like tab separator : write a field, then chr(9), then the other field, and so on.
Afterward, you will obtain a readable text file, but you will be able to separate fields again by splitting the input.
Hi, thanks for the info, I found a real good video tutorial on Youtube and followed it, I have it working now.
Here is the youtube video that helped me in creating a menu with a save and open option, very helpful to see someone create it: https://youtu.be/3JXWSIjideI
you may go there to download Introduction to Programming with Xojo 3rd Edition (2016) and download either the eBook / pdf (with example).
It have parts to load text and save text and much more.
Nice to see, watch and read.
thanks Emile, I will have a look.