Passing variables to GetFolderItem

I’m trying to pass variable values from a list box to GetFolderItem() without success. What is the correct syntax?

dim f as New folderitem
f=GetFolderItem(CurrentBook).Child(CurrentBook).Child(CurrentChapter).Child(CurrentVerse)
if f.exists then
msgBox(“File exists”)
end if

The error returned is: NilObjectException

The variables are initialized with values in the Change event of a listbox

currentVerse=Me.Cell(Me.Listindex,3)
CurrentBook=Me.Cell(Me.Listindex,4)
CurrentChapter=Me.Cell(Me.Listindex,5)

The variables are populated correctly as text strings and display properly using the msgBox() function

Did you really mean to use CurrentBook twice?

The LR is your friend : http://documentation.xojo.com/index.php/GetFolderItem

If f is nil chances are one of the folders is not right.

Tim, yes. the ‘CurrentBook’ is in the tree on purpose. The directory structure is designed to support an app from Xojo or a web page environment.

Michael, the LR didn’t seem to address using variables. The values returned from the listbox change event are valid.

[quote=226552:@Ben Joyner]Tim, yes. the ‘CurrentBook’ is in the tree on purpose.

Michael, the LR didn’t seem to address using variables. The values returned from the listbox change event are valid.[/quote]

Using variables or not, you want to make sure the folderitem tree is valid.

f=GetFolderItem(CurrentBook).Child(CurrentBook).Child(CurrentChapter).Child(CurrentVerse)

This translates the following path : /CurrentBook/CurrentBook/CurrentChaper/CurrentVerse

Is the first CurrentBook at the root of the current volume, or is it within Documents ?

Only you know the values of these strings. If one is invalid, your entire folderitem will be.

That’s what is throwing me.

dim f as New folderitem
//f=GetFolderItem(CurrentBook).Child(CurrentBook).Child(CurrentChapter).Child(CurrentVerse)
f=GetFolderItem(“01_Genesis”).Child(“01_Genesis”).Child(“01_Genesis_001”).Child(“0001.mp3”)
if f.exists then
msgBox(“File exists”)
end if
msgbox(CurrentBook+" “+CurrentChapter+” "+CurrentVerse)

The f.exist returns true for the modified GetFolderItem() to include “text strings”

The msgBox() returns “01_Genesis” “01_Genesis_001” “0001.mp3”

I try to understand what I can but sometimes I don’t worry about it. I moved the routine to a method with the parameters
needed; cb as string, cc as string, cv as string.

Then on the change event pass the data to the method.

One of my issues was that I need to test that any of the passed parameters was actually populated.

Poof, problem solved.

You need to put it in a try catch because if it’s more than one level invalid you’re going to get the nilobjectexception instead of the false .exists result.

[iPhone brevity disclaimer]

Caught (no pun intended) when I tested it against a folder that wasn’t populated. Thanks for the tip.