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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Questions about Modularizing Code 1

Status
Not open for further replies.

Brycspain

IS-IT--Management
Mar 9, 2006
150
US
I’ve attached a few subs and was having difficulty getting my main sub to read the sub with the dictionary object code. It works great when I add the dictionary code inside the main sub but I wanted to make it look cleaner…is there a way to do it the way I’m trying?

This is the line I’m having trouble with: It’s the main sub line 21
strOU = dictionaryOU( aStr(10) )

Any help would be appreciated.

Code:
'------------------------------------------------------------------------------------------------------
'Subroutine for main part of the script
Sub Main
Dim oFile, sInputFile, oFSO
Const ForReading = 1
sInputFile = "\\fay-dc01\adduser$\HeatAD.csv" 
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(sInputFile, ForReading )
Do While Not oFile.AtEndOfStream
aStr = split(oFile.ReadLine,",")    
sLogon = aStr(0)    
sFirstName = aStr(1)    
sMiddleInit = aStr(2)
sLastName = aStr(3)
sDescription = aStr(4)    
sCopyUser = aStr(5)
sMailcluster = aStr(6)
sStorageGroup = aStr(7)
sMailStore = aStr(8)
sSGCapacity = aStr(9)
[b]strOU = dictionaryOU( aStr(10) )'call sub to convert[/b] abbreviated OU to full path
sEmployeeID = aStr(11)
sHomeFiler = aStr(12)
sAdminUser = aStr(13)
sCompTech = aStr(14)

Checknames 'sub to check for first and last name..if one is missing, halt script
Builduseraccount 'sub to build basic user account   
ActivateAccount 'sub to activate the account
CopyGroups 'sub to copy group memberships
termsvspath 'sub to add the terminalservicespath to the account
CreateMailbox 'sub to create mailbox
HomeFolder 'sub to create home folders
RootFolder 'sub to create root drive folders
NewuserCheck 'sub to check if user was created

' Move ahead to the next record
Loop

'close the csv file
oFile.close

EmailLog 'sub to email log file
End Sub

'---------------------------------------------------------------------------------------------------
'Subroutine to create the dictionary of abbreviations for OU's
Sub dictionaryOU
Dim dctOU
Set dctOU = CreateObject("Scripting.Dictionary")
dctOU.Add "AWG","OU=Users-AWG,OU=Users-Fayetteville,"
dctOU.Add "GASCONTROL","OU=Users-GASCONTROL,OU=Users-Fayetteville,"
dctOU.Add "INDPARK","OU=Users-Industrial Park,OU=Users-Fayetteville,"
dctOU.Add "FAYSEECO","OU=Users-SEECO,OU=Users-Fayetteville,"
dctOU.Add "FAYSWN","OU=Users-SWN,OU=Users-Fayetteville,"
dctOU.Add "HOU","OU=Users-Houston,"
dctOU.Add "IS","OU=Users-IS Dept,"
dctOU.Add "BLYLNG","OU=Blytheville-LNG,OU=Users-Remote Offices,"
dctOU.Add "BLYOPS","OU=Blytheville-Ops,OU=Users-Remote Offices,"
dctOU.Add "CON","OU=Conway,OU=Users-Remote Offices,"
dctOU.Add "DAM","OU=Damascus,OU=Conway,OU=Users-Remote Offices,"
dctOU.Add "DESOTORIGMAN","OU=Desoto Rig Managers,OU=Conway,OU=Users-Remote Offices,"
dctOU.Add "HEBSPR","OU=Heber Springs, OU=Users-Remote Offices,"
dctOU.Add "HOBBS","OU=Hobbs, OU=Users-Remote Offices,"
dctOU.Add "LOCALAWGOFF","OU=Local AWG Offices, OU=Users-Remote Offices,"
dctOU.Add "MORIL","OU=Morillton, OU=Users-Remote Offices,"
dctOU.Add "OVERFIELDOFF","OU=Overton Field Office, OU=Users-Remote Offices,"
dctOU.Add "OZADRAKEANDSELLS","OU=Ozark Drake And Sells, OU=Users-Remote Offices,"
dctOU.Add "OZASEECO","OU=Ozark Seeco, OU=Users-Remote Offices,"
dctOU.Add "SATDRILLRIG","OU=Satellite Drilling Rigs, OU=Users-Remote Offices,"
dctOU.Add "UNIONNONEXP","OU=Union - NonExpiring, OU=Users-Remote Offices,"
dctOU.Add "CONTRACT-NONEMP","OU=Users-Contract-NonEmployee,"
dctOU.Add "TEST","OU=Users-Test Group,"
End Sub
'---------------------------------------------------------------------------------------------------
 
Instead of a Sub use a function

Function dictionaryOU(strOU)
...code
dictionaryOU = dctOU(strOU)
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
KISS right DM? Man, you're getting good at this stuff...you should think about a career change and start doing rocket science.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top