Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Loop to Create Single Object

Status
Not open for further replies.

jmikow

Programmer
Mar 27, 2003
114
0
0
US
I have been working with an API for a software application that we have in our office and I am unsure about how to get past this point.

The API calls for everything to be of type "Object". I have a specific part of it that i need to be able to loop through and create an object out of a string. I have been able to do this, but it makes the variable now be of type string instead of "Object".

Here's an example of what I know works:
Code:
        Dim database As Object, folder As Object
        database = fortApp.Databases(configData.ImagingDBName)
        folder = database.RootFolder.Folders(TextBox1.Text).Folders(TextBox4.Text)

The reason it works is that I know that the path to the "folder" is 2 folders deep.

My problem is that I need to be able to specify a path to the folder and have it be varying levels deep. I want to be able to have folder be either 3, 4 or 5 levels deep depending on the path I send in.

Here is the code that I have tried but does not work:
Code:
        Dim i As Integer
        Dim folderNames() As String = configData.FolderPath.Split(";")
        Dim folderStr As String
        folderStr = "database.RootFolder" 
        For i = 0 To folderNames.Length - 1
            folderStr = folderStr & ".Folders(" & folderNames(i) & ")"
        Next
        folder = CType(folderStr, Object)
After this code is run the object "folder" is now of type "String" instead of "Object".

Any ideas or comments would be appreciated.

Thanks,

Josh
 
Dim a variable of whatever type .Folders(TextBox1.Text) returns to you (a Folder object, maybe??) and do something like this:
[tt]
l = 1
f = Folders(foldernames(l))
while ((f <> Nothing) and (l < foldernames.length))
l = l + 1
f = f.Folders(foldernames(l))
end while
[/tt]
You'll also need an array of foldernames that got loaded from your textboxes.

Chip H.

____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top