Sam
Sam

Reputation:

Recursive list with vbscript

I have a csv file with userid and manager fields. How can I list all userids that report to a specific manager and its direct reports, drilled down to the last user. Need a quick vbscript.

Thanks.

Upvotes: 0

Views: 728

Answers (1)

Tomalak
Tomalak

Reputation: 338128

Open the CSV file via ADODB.

You need a <final_result> variable (initially empty), and a <managers> variable (initially the ID of the one manager you want to create a list for).

Then write a loop that does:

  1. SELECT DirectReports FROM TextFile WHERE Manager IN ('<managers>')
  2. create a list of the DirectReports IDs from the resulting RecordSet
  3. append that list to the <final_result> variable
  4. assign to the <managers> variable a comma delimited string: "'<id1>','...','<idn>'"
  5. start at #1 unless list is empty

When the loop is through, the final result variable holds all the direct reports.

See - no recursion required. Plain iteration is enough.

Upvotes: 2

Related Questions