Your original code, as posted, will only put every second line into the listbox. You should be sure that you do as Jeff suggested and read each line into a variable.
Further, if the second of your readline calls happens to be the one that encounters “Money”, then it’ll put that into the listbox and you’ll continue reading up to EOF.
[quote=447083:@Tim Streater]Your original code, as posted, will only put every second line into the listbox. You should be sure that you do as Jeff suggested and read each line into a variable.
Further, if the second of your readline calls happens to be the one that encounters “Money”, then it’ll put that into the listbox and you’ll continue reading up to EOF.[/quote]
Maybe to clarify Tim’s reply, each time you call t.ReadLine it reads a new line, so the line you are reading in your if… then block is different from the line you are actually adding to the listbox.
(I had previously posted a reply but has not appeared; Iam reposting it below)
Emile, Jeff, Tim, Carlo and Julen,
thank you for taking time to sharing your expertise. I have made changes suggested your posts and it now works. You have made my day! Wishing you a great weekend!
The modified code that works:
Dim myfile as FolderItem
Dim d as OpenDialog
Dim t as TextInputStream
d=New OpenDialog
Dim enc As TextEncoding
myFile=d.ShowModal
ListBoxTodo.DeleteAllRows
If myFile<>Nil Then
t=TextInputStream.Open(myFile)
enc = t.Encoding ’
While Not t.EOF
dim v as string
dim s as integer
v=t.ReadLine
v=trim(v)
if Left(v,5)="Money" then
Exit
Else
ListBoxTodo.AddRow(v)
end if
Wend
Dim i as Integer
Redim ToDoList(-1)
For i = 0 to ListboxTodo.Listcount -1
ToDoList.Append(ListboxTodo.list(i)) // assign a name to each index in the array
next
Dim enc As TextEncoding//remove it
myFile=d.ShowModal
ListBoxTodo.DeleteAllRows
If myFile<>Nil Then
t=TextInputStream.Open(myFile)
enc = t.Encoding '//remove it
I’d re-write the above snippet as shown in the example in Language Reference > TextInputStream:
myFile=d.ShowModal
ListBoxTodo.DeleteAllRows
If myFile<>Nil Then
t=TextInputStream.Open(myFile)
t.encodings = encodings.UTF8
And why not do everything in one go? No more need to build the array at the end.
ListBoxTodo.DeleteAllRows
Redim ToDoList(-1)
If myFile<>Nil Then
// your code above, until:
Else
ListBoxTodo.AddRow(v)
ToDoList.Append v
end if
wend