I did the test using Ubound and the code appears to work perfectly. A more elegant solution than my original “brute force” method so many thanks for that Kem.
I’m trying to get my mind around the ReplaceLineEndings code you posted. I did a bit of research and it’s looks like something that probably should be implemented, but at this stage I’m happy that it’s working on a Windows machine. Perhaps a future refinement for version 2.0?
Although, when I think about it, apart from reading from the serial port, would the ReplaceLineEndings code be required for reading in a text file on another OS?
I find that with my programming style, I tend to spend too much time worrying about “what if’s” than getting things done.
Thanks to all, I consider my original question answered/solved. How can this be summarised for me to post “this answers my question”
ReplaceLineEndings will normalize the EOL of a text file so you don’t have to worry about its origin. So yes, it’s a good idea generally speaking.
For example, consider the case of reading a Windows-originated text file on the Mac or Linux. Suppose your code looks like this:
dim tis as TextInputStream = TextInputStream.Open( winFile )
dim contents as string = tis.ReadAll
tis.Close
dim linesArr() as string = contents.Split( EndOfLine )
At this point, Split will appear to have worked and linesArr will be populated, but what you won’t see unless you look closely is that each line will end with an invisible CR. Why? Because the Windows EOL sequence is CR+LF while Mac/Linux use just LF, and that’s what EndOfLine represents on Mac and Linux. Split will do what it’s told and break each line on the LF, leaving the CR behind.
Coding defensively - I like that very much. That’s always been my approach but more so with the user in mind than the os.
Xojo is the first programming language that I’ve used that can be easily moved across operating systems. Therefore decisions have to be made regarding portability.
At this point, I’m purely writing the software for myself (Windows OS). The hardware and electronics side (load cell etc.) has taken many months to develop and now the software needs to be created as the other half of the final solution.
There may well be opportunities to sell the hardware & software together to a very limited market, but at this point it’s purely personal.