load a file back into listbox (Urgent)

I figured out how to mousedrag, but I don’t know how to load a file back into the listbox; I’ve tried this:

in listbox1.open I’ve stated the heading and column count per usual, then I have a pushbutton to add the items into the listbox and I have the labels and textfields for the categories.

Now, this is what I need help in:

I have two methods, one for loadscore and the second for savescore:

LoadScore:
Dim loadFile As FolderItem
loadFile = GetFolderItem ("/Desktop/Lexar/summative#1/newson_newson/")

If loadFile <> Nil And loadFile.Exists Then
Dim input As TextInputStream
input = TextInputStream.Open(loadFile)
mScore = Val(input.ReadLine)
input.Close
End If

SaveScore:
Dim f As FolderItem
f = GetFolderItem ("/Desktop/lexar/summative#1/newson_newson",1)

dim t as TextOutputStream

If f.Exists = False Then
t = TextOutputStream.Create(f) //create folder
End If

Dim saveFile As FolderItem
saveFile = GetFolderItem (“Newson_Newson”)

Dim output As TextOutputStream
output = TextOutputStream.Create(saveFile)
output.WriteLine(Str(mScore))
output.Close

then I have a pushbutton to save the information onto a file and its name is ‘score’ containing this code:
dim f as FolderItem

'f = GetFolderItem ("/Desktop/lexar/summative#1/newson_newson",1)

Dim t as TextOutputStream

if f.Exists = False then //if folder does not exist
t = TextOutputStream.Create(f) //create folder
SaveScore
else
//does exist
t = TextOutputStream.Append(f) //add on
SaveScore
end if

(My problem is that whenever I click on the ‘save’ pushbutton I am forced back into the app window and a list comes up that states that f and t have an exception of Nil now I now what that means but I don’t know how to deal with it.)

\\ I wrote about this last week but didn’t know how to edit that post thus my sincere apology for this.\\

Which line has the exception? The way to handle an NilObjectException is to test each object for Nil before you use it.

GetFolderItem may return nil if the path you pass it is impossible - one or more of the intermediate folders do not exist. It is permissible for the terminal portion of the path to not exist, but all the other folders in the path must exist.

You use

if f.Exists = false then

without testing whether f is Nil or not.

TextOutputStream.Create will not return nil. It will throw an IOException.

This code will always throw a NilObjectException because you have commented out the GetFolderItem.

'f = GetFolderItem ("/Desktop/lexar/summative#1/newson_newson",1)

Dim t as TextOutputStream

if f.Exists = False then //if folder does not exist
t = TextOutputStream.Create(f) //create folder
SaveScore
else
//does exist
t = TextOutputStream.Append(f) //add on
SaveScore
end if

Note also that you go through the motions of creating a file /Desktop/lexar/summative#1/newson_newson, but you never use it. Your save code creates a separate file next to the executable, not in the above mentioned path.

Note also that you go through the motions of creating a file /Desktop/lexar/summative#1/newson_newson, but you never use it. Your save code creates a separate file next to the executable, not in the above mentioned path.[/quote]

Does that mean that there is another way of doing it and that my way is wrong?

I tried to have only

t = TextOutputStream.Append(f) //add on

but it gave me the same thing…

You have two code examples here.
Did you try it first (with some adaptations if needed) ?

One example (from the doc is) is:

Dim t As TextOutputStream Dim f As FolderItem f = GetSaveFolderItem("", "CreateExample.txt") If f <> Nil Then t = TextOutputStream.Create(f) t.WriteLine(TextField1.Text) t.Close End If

Also, instead of:

If loadFile <> Nil And loadFile.Exists Then Dim input As TextInputStream input = TextInputStream.Open(loadFile) mScore = Val(input.ReadLine) input.Close End If

You may add an Else part (before End If) and report that an error occured…

or use:

[code]If loadFile = Nil And Not loadFile.Exists Then // I do not recall if we must use And or OR
// Issue an error to the user
// and stop the code running here
Return
End If

Dim input As TextInputStream
input = TextInputStream.Open(loadFile)
mScore = Val(input.ReadLine)
input.Close
[/code]

HTH.