Help with code conversion C# to VB


T

Ty

The top block is the original code (I have already tried automatic
convertors but they error everytime.) and the second block is what I
have done. At the end will be the line that has me stumped.

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional
$OrderBy,Optional $Scope,
Optional $User,Optional $Pswd)

Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R

$sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://
rootDSE").Get("defaultNamingContext"),
$From)+">;"+$Filter
+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)

$oCon=CreateObject("ADODB.Connection")
$oCon.Provider="ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If InStr($OrderBy,"distinguishedName")
$oRS=CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS=$oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
For $R=0 to Ubound($aR,2)
For $C=0 to Ubound($aR,1)
$aFR[$R,$C]=$aR[$C,$R]
Next
Next

$fnLDAPQuery=$aFR
EndFunction


************************************************************************************************************************************

Function fnLDAPQuery(What As String, Optional From As String, Optional
Filter As String,Optional OrderBy As String,Optional Scope As
String,Optional User As String,Optional Pswd As String)

Dim oCon As ADODB.Connection
Dim oCMD As ADODB.Command
Dim oRS As ADODB.Recordset
Dim sQ As String
Dim aR As Array
Dim C As Integer
Dim R As Integer

sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)

oCon = New ADODB.Connection
oCon.Provider = "ADsDSOObject"
oCon.Properties("Encrypt Password").Value = 1
oCon.Properties("ADSI Flag").Value = 1
If User And Pswd Then
oCon.Properties("User ID").Value = User
oCon.Properties("Password").Value = Pswd
End If
oCon.Open("Active Directory Provider")

oCMD = New ADODB.Command
oCMD.ActiveConnection = oCon
oCMD.CommandText = sQ
oCMD.Properties("Page Size").Value = 1000
oCMD.Properties("Timeout").Value = 30
oCMD.Properties("Cache Results").Value = 0

If InStr(OrderBy, "distinguishedName") Then
oRS = New ADODB.Recordset
oRS.CursorLocation = 3
oRS.Sort = OrderBy
oRS.Open(sQ, oCon, 0, 1, 1)
Else
If OrderBy Then
oCMD.Properties("Sort On").Value = OrderBy
End If
oRS = oCMD.Execute
End If
'If ERROR Exit ERROR EndIf
If oRS.BOF And oRS.EOF Then
Else
aR = oRS.GetRows()
Dim aFR(UBound(aR, 2), UBound(aR, 1))
For R = 0 To UBound(aR, 2)
For C = 0 To UBound(aR, 1)
aFR(R, C) = aR(C, R)
Next
Next

fnLDAPQuery = aFR
End If

End Function()

The line that has an error showing that I cannot figure out how to fix
is

sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)

The purpose of this is the get information from Active Directory. I
was looking for code to get all the users and some of the properties
and this looked promissing.

Thanks,
Ty
 
Ad

Advertisements

L

Lloyd Sheen

Ty said:
The top block is the original code (I have already tried automatic
convertors but they error everytime.) and the second block is what I
have done. At the end will be the line that has me stumped.

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional
$OrderBy,Optional $Scope,
Optional $User,Optional $Pswd)

Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R

$sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://
rootDSE").Get("defaultNamingContext"),
$From)+">;"+$Filter
+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)

$oCon=CreateObject("ADODB.Connection")
$oCon.Provider="ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If InStr($OrderBy,"distinguishedName")
$oRS=CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS=$oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
For $R=0 to Ubound($aR,2)
For $C=0 to Ubound($aR,1)
$aFR[$R,$C]=$aR[$C,$R]
Next
Next

$fnLDAPQuery=$aFR
EndFunction


************************************************************************************************************************************

Function fnLDAPQuery(What As String, Optional From As String, Optional
Filter As String,Optional OrderBy As String,Optional Scope As
String,Optional User As String,Optional Pswd As String)

Dim oCon As ADODB.Connection
Dim oCMD As ADODB.Command
Dim oRS As ADODB.Recordset
Dim sQ As String
Dim aR As Array
Dim C As Integer
Dim R As Integer

sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)

oCon = New ADODB.Connection
oCon.Provider = "ADsDSOObject"
oCon.Properties("Encrypt Password").Value = 1
oCon.Properties("ADSI Flag").Value = 1
If User And Pswd Then
oCon.Properties("User ID").Value = User
oCon.Properties("Password").Value = Pswd
End If
oCon.Open("Active Directory Provider")

oCMD = New ADODB.Command
oCMD.ActiveConnection = oCon
oCMD.CommandText = sQ
oCMD.Properties("Page Size").Value = 1000
oCMD.Properties("Timeout").Value = 30
oCMD.Properties("Cache Results").Value = 0

If InStr(OrderBy, "distinguishedName") Then
oRS = New ADODB.Recordset
oRS.CursorLocation = 3
oRS.Sort = OrderBy
oRS.Open(sQ, oCon, 0, 1, 1)
Else
If OrderBy Then
oCMD.Properties("Sort On").Value = OrderBy
End If
oRS = oCMD.Execute
End If
'If ERROR Exit ERROR EndIf
If oRS.BOF And oRS.EOF Then
Else
aR = oRS.GetRows()
Dim aFR(UBound(aR, 2), UBound(aR, 1))
For R = 0 To UBound(aR, 2)
For C = 0 To UBound(aR, 1)
aFR(R, C) = aR(C, R)
Next
Next

fnLDAPQuery = aFR
End If

End Function()

The line that has an error showing that I cannot figure out how to fix
is

sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)

The purpose of this is the get information from Active Directory. I
was looking for code to get all the users and some of the properties
and this looked promissing.

Thanks,
Ty
First off it is not C# that is the original.

Second what is the error message???

It looks as if you need continuation characters on the line that you
indicate.

LS
 
Ad

Advertisements

T

Ty

The top block is the original code (I have already tried automatic
convertors but they error everytime.) and the second block is what I
have done. At the end will be the line that has me stumped.
Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional
$OrderBy,Optional $Scope,
   Optional $User,Optional $Pswd)
   Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
   $sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://
rootDSE").Get("defaultNamingContext"),
       $From)+">;"+$Filter
+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+
       Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
   $oCon=CreateObject("ADODB.Connection")
   $oCon.Provider="ADsDSOObject"
   $oCon.Properties("Encrypt Password").Value=1
   $oCon.Properties("ADSI Flag").Value=1
   If $User AND $Pswd
       $oCon.Properties("User ID").Value=$User
       $oCon.Properties("Password").Value=$Pswd
   EndIf
   $oCon.Open("Active Directory Provider")
   $oCMD=CreateObject("ADODB.Command")
   $oCMD.ActiveConnection=$oCon
   $oCMD.CommandText=$sQ
   $oCMD.Properties("Page Size").Value=1000
   $oCMD.Properties("Timeout").Value=30
   $oCMD.Properties("Cache Results").Value=0
   If InStr($OrderBy,"distinguishedName")
       $oRS=CreateObject("ADODB.Recordset")
       $oRS.CursorLocation=3
       $oRS.Sort=$OrderBy
       $oRS.Open($sQ,$oCon,0,1,1)
   Else
       If $OrderBy
           $oCMD.Properties("Sort On").Value=$OrderBy
       EndIf
       $oRS=$oCMD.Execute
   EndIf
   If @ERROR Exit @ERROR EndIf
   If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf
   $aR = $oRS.GetRows()
   Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
   For $R=0 to Ubound($aR,2)
       For $C=0 to Ubound($aR,1)
           $aFR[$R,$C]=$aR[$C,$R]
       Next
   Next
   $fnLDAPQuery=$aFR
EndFunction

Function fnLDAPQuery(What As String, Optional From As String, Optional
Filter As String,Optional OrderBy As String,Optional Scope As
String,Optional User As String,Optional Pswd As String)
       Dim oCon As ADODB.Connection
       Dim oCMD As ADODB.Command
       Dim oRS As ADODB.Recordset
       Dim sQ As String
       Dim aR As Array
       Dim C As Integer
       Dim R As Integer
       sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)
       oCon = New ADODB.Connection
       oCon.Provider = "ADsDSOObject"
       oCon.Properties("Encrypt Password").Value = 1
       oCon.Properties("ADSI Flag").Value = 1
       If User And Pswd Then
           oCon.Properties("User ID").Value = User
           oCon.Properties("Password").Value = Pswd
       End If
       oCon.Open("Active Directory Provider")
       oCMD = New ADODB.Command
       oCMD.ActiveConnection = oCon
       oCMD.CommandText = sQ
       oCMD.Properties("Page Size").Value = 1000
       oCMD.Properties("Timeout").Value = 30
       oCMD.Properties("Cache Results").Value = 0
       If InStr(OrderBy, "distinguishedName") Then
           oRS = New ADODB.Recordset
           oRS.CursorLocation = 3
           oRS.Sort = OrderBy
           oRS.Open(sQ, oCon, 0, 1, 1)
       Else
           If OrderBy Then
               oCMD.Properties("Sort On").Value = OrderBy
           End If
           oRS = oCMD.Execute
       End If
       'If ERROR Exit ERROR EndIf
       If oRS.BOF And oRS.EOF Then
       Else
           aR = oRS.GetRows()
           Dim aFR(UBound(aR, 2), UBound(aR, 1))
           For R = 0 To UBound(aR, 2)
               For C = 0 To UBound(aR, 1)
                   aFR(R, C) = aR(C, R)
               Next
           Next
           fnLDAPQuery = aFR
       End If
End Function()
The line that has an error showing that I cannot figure out how to fix
is
sQ = "<" & IIf(From = "", "LDAP://" & GetObject("LDAP://
rootDSE").Get("defaultNamingContext"), From) & ">;" & Filter & ";" &
IIf(VarType(What) > 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <> "onelevel", "subtree", Scope)
The purpose of this is the get information from Active Directory. I
was looking for code to get all the users and some of the properties
and this looked promissing.
Thanks,
Ty
First off it is not C# that is the original.

Second what is the error message???

It looks as if you need continuation characters on the line that you
indicate.

LS- Hide quoted text -

- Show quoted text -
The line was split up by this message viewer. The error is in the code
window and it is on this part .
Join(What, ","), What)
something about that join statement is not liked.

Ty
 

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