Newbie Question - Visual Basic .NET Express 2005 & syntax

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to get some code that will go into Active Directory and extract
the legacyExchangeDN attribute for every user in a domain. I know nothing
about VB, so I would like help with fixing the error below. My only
programming experience prior to this would be Assembly Language for the 6502
(Apple ][E) when I was 12-16yrs old. Never done basic before.

This code works fine when run as VBscript (using cscript), but won't compile
with VB.

The error I get in the Error List window is as follows:
'Array' is a type and cannot be used as an expression

Here is the code. It is a command-line project in VBXpress 2005, and this
is the code in Module1.vb (the only module):

Dim outFile, domain, fs, f
outFile = "castellan_users.txt"
domain = "LDAP://dc=castellan,dc=net"

' Open text file for writing
Const ForWriting = 2

fs = CreateObject("Scripting.FileSystemObject")
f = fs.OpenTextFile(outfile, ForWriting, True)

DisplayObjects(domain, "")

f.Close()

' DisplayObjects takes the ADsPath of the object to display
' child objects for and the number of spaces (indention) to
' use when printing the first parameter
End Sub

Function DisplayObjects( strADsPath, strSpace)
Dim objobject, objChildObject
objObject = GetObject(strADsPath)
If InStr(strAdsPath, "LDAP://OU") <> 0 Then ListUsers(strADsPath)
If InStr(strAdsPath, "LDAP://CN") <> 0 Then ListUsers(strADsPath)
objObject.Filter = Array("container", "organizationalUnit")
For Each objChildObject In objObject
DisplayObjects(objChildObject.ADsPath, strSpace & " ")
Next

End Function

Sub ListUsers(ByVal strDomain)
Dim objComputer, objUser, f
objComputer = GetObject(strDomain)
objComputer.Filter = Array("User")
For Each objUser In objComputer
f.WriteLine(objUser.legacyexchangeDN)
Next
End Sub
 
Try replacing the Array function with manually creating an array variable and
adding the necessary values in that.

Eg.
Dim x(2) As String
x(0) = "container"
x(1) = "organizationalUnit"
 
Back
Top