enumeration help needed

K

Keith G Hicks

I want to run through an enumeration in a loop for scanning client sub
folders.

Base folder is D:\TestStuff\

Subfolders in that are Jones, Smith, Ryan (there could be several more and
will not be named this simple)

I want to run a loop that goes through those folders one at a time like
this:

For x = Jones to Ryan
.... check for files in each sub folder and do a bunch of processing
Next x

I thought I could do soemthing with enumerations where the enum would be
defined like this:

Private enum clientFolders
Jones = 1
Smith = 2
Ryan = 3
End Enum

Then I could do something like this

For x = 1 to 3
msgbox(clientFolders.x)
next x


But that doens't work. I'm not sure how to do this.

Thanks,

Keith
 
K

Keith G Hicks

I think I figured this out. Seems kind of convoluted but it works.

Private Enum clientName
Jones
Smith
Ryan
End Enum


Dim clientFolderName As Type = GetType(clientName)
Dim x As String
For Each x In [Enum].GetNames(clientFolderName)
MsgBox(x)
Next
 
C

Chris Dunaway

I think I figured this out. Seems kind of convoluted but it works.

Private Enum clientName
    Jones
    Smith
    Ryan
End Enum

Dim clientFolderName As Type = GetType(clientName)
Dim x As String
For Each x In [Enum].GetNames(clientFolderName)
    MsgBox(x)
Next

Keith G Hicks said:
I want to run through an enumeration in a loop for scanning client sub
folders.
Base folder is D:\TestStuff\
Subfolders in that are Jones, Smith, Ryan (there could be several more and
will not be named this simple)
I want to run a loop that goes through those folders one at a time like
this:
For x = Jones to Ryan
   .... check for files in each sub folder and do a bunch of processing
Next x
I thought I could do soemthing with enumerations where the enum would be
defined like this:
Private enum clientFolders
   Jones = 1
   Smith = 2
   Ryan = 3
End Enum
Then I could do something like this
For x = 1 to 3
   msgbox(clientFolders.x)
next x
But that doens't work. I'm not sure how to do this.

Keith

In addition to Patrice's comments, what will you do when you decide to
add another user in the future? Are you going to change your code
every time?

You might be better off using the System.IO.Directory.GetDirectories
method to get the list of directories in the d:\teststuff folder:

Dim clientFolders() As String = System.IO.Directory.GetDirectories("c:
\teststuff")
For Each folder As String in clientFolders
'Do stuff with folder here
Next

This code will work, even if you add more folders to c:\teststuff.
 
K

Keith G Hicks

I think I figured this out. Seems kind of convoluted but it works.

Private Enum clientName
Jones
Smith
Ryan
End Enum

Dim clientFolderName As Type = GetType(clientName)
Dim x As String
For Each x In [Enum].GetNames(clientFolderName)
MsgBox(x)
Next

I want to run through an enumeration in a loop for scanning client sub
folders.
Base folder is D:\TestStuff\
Subfolders in that are Jones, Smith, Ryan (there could be several more
and
will not be named this simple)
I want to run a loop that goes through those folders one at a time like
this:
For x = Jones to Ryan
.... check for files in each sub folder and do a bunch of processing
Next x
I thought I could do soemthing with enumerations where the enum would be
defined like this:
Private enum clientFolders
Jones = 1
Smith = 2
Ryan = 3
End Enum
Then I could do something like this
For x = 1 to 3
msgbox(clientFolders.x)
next x
But that doens't work. I'm not sure how to do this.

In addition to Patrice's comments, what will you do when you decide to
add another user in the future? Are you going to change your code
every time?

Yes. I am. First, they're not users, they're clients. Second, the code is
for importing data from spreadsheets submitted by the clients and each
client has a different layout so the code is entirely different in each
case. Each time a new client is going to be added to this process, I will be
writing a new hunk of code specifically for that client. So yes, it won't
happen very often but I will have to rewrite the code each time. I know how
to scan for folders. Just can't make use of that idea in this case at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top