enumeration help needed

  • Thread starter Thread starter Keith G Hicks
  • Start date Start date
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
 
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 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.
 
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.
 
Back
Top