[code]Dim f As FolderItem = GetOpenFolderItem(“text”)
If f <> Nil Then
If f.Exists Then
// Be aware that TextInputStream.Open could raise an exception
Dim t As TextInputStream
Try
t = TextInputStream.Open(f)
TextArea1.Text = t.ReadAll //(Encodings.WindowsANSI)
t.Close
Catch e As IOException
MsgBox(“Error accessing file.”)
End Try
End If
End If[/code]
This works as expected with TextArea1 being populated (for my review purposes only).
Then I’ve tried to populate the array like this:
[code] redim tempArray(-1)
dim importedData as String
importedData = TextArea1.Text
tempArray = importedData.Trim.Split(EndOfLine.Windows)
//test
MsgBox str(tempArray.Ubound)[/code]
The MsgBox returns 0, therefore the array is empty.
Ultimately I would prefer not to have the TextArea, this is just temporary for me to check. It would be better if the array was populated directly from the file. I guess I could use ReadLine and loop until EOF, instead of ReadAll - but thought this would be more efficient.
Thanks Roger. Yes, I guess there is one element.
“TmpArray() = split(importedData, endOfLine)” still doesn’t make any difference though.
However, I’ve discovered something: If I change the message box to MsgBox str(tempArray(0)) ie. zero instead of Ubound, I now get ALL of the data file showing in the message box. So, the whole of the data is being assigned to the first element of the array and not being split. At least that’s something.
I’ve been mucking around with this for the last few hours and getting nowhere fast.
This has been a break-through moment in my software and programming with Xojo. I’ve been working on the other parts and putting off File IO until now. I’ve learned a lot .
An often overlooked function is ReplaceLineEndings. That will let you normalize the EOL characters in a string before you process it, and is considered good practice especially when reading from a file whose originating platform is unknown.