Read from a text file

Files have me totally buffaloed.

All I want to do is open and read from a text file that contains a series of comma delimited text lines. The filename is fixed (“wisparam.txt”) and there is no user interaction to select it - it is hardwired into the code. I can’t figure out how to open the file correctly so it can be read from.

I tried:

dim infile as folderitem
infile=“wisparam.txt”
dim input as TextInputStream
input=TextInputStream.open(InFile)

But I get an error that says Type mismatch. Expected class FolderItem, but got TextLiteral infile=”wisparam.txt”

In my old QBASIC programming days, I’d open a file just by:

open “wisparam.txt” for input as #1

Things are a lot more complicated in XOJO.

You are close. I remember QBASIC too. But Xojo starts to make sense after a while.

All of these do the same thing:

'option 1
var inFile as FolderItem
inFile = New FolderItem(“c:\abc\winsparam.txt”, FolderItem.PathModes.Native)

var ti as TextInputStream
ti= TextInputStream.Open(inFile)

'option 2
var inFile2 as New FolderItem(“c:\abc\winsparam.txt”, FolderItem.PathModes.Native)
var ti2 as TextInputStream = TextInputStream.Open(inFile2)

'option 3
var ti3 as TextInputStream = TextInputStream.Open(New FolderItem(“c:\abc\winsparam.txt”, FolderItem.PathModes.Native))

Hi @Gerald_Mahun - don’t get too discouraged (yet!) :wink:

Take a few minutes to scroll through FolderItem to get familiar with it. That should give you some ideas.

If your file is not changed in time (read only its contents ad vitam), do this:

Drop the file into your Navigation pane,
Use wisparam as a String variable when you need its contents.

This is like if you have created a String variable and filed it with the text file contents.

At compile time, your text file is included inside the Application.

special folder is also nice to use

= SpecialFolder.Documents.Child("wisparam.txt")

at TextInputStream use .ReadAll

there is a example at ReadLine