473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with code conversion C# to VB

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
Jun 27 '08 #1
2 1304

"Ty" <tb*****@lewistownhospital.orgwrote in message
news:22**********************************@m44g2000 hsc.googlegroups.com...
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

Jun 27 '08 #2
Ty
On May 15, 7:11*pm, "Lloyd Sheen" <a...@b.cwrote:
"Ty" <tbar...@lewistownhospital.orgwrote in message

news:22**********************************@m44g2000 hsc.googlegroups.com...


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
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
2
by: Thames | last post by:
Hi, I have to repost my question for help. Yesterday I set up two DB UDB ESE V8.2 server on linux and windows platform, respectively. Both servers have been connected without any problems...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
1
by: Dancefire | last post by:
Hi, everyone, I'm trying to use std::codecvt<to do the encoding conversion. I am using following code for encoding conversion between wchar_t string and char string(MBCS). I am not sure am I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.