473,608 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($Wh at,Optional $From,Optional $Filter,Optiona l
$OrderBy,Option al $Scope,
Optional $User,Optional $Pswd)

Dim $oCon,$oCMD,$oR S,$sQ,$aR,$C,$R

$sQ="<"+Iif($Fr om="","LDAP://"+GetObject("LD AP://
rootDSE").Get(" defaultNamingCo ntext"),
$From)+">;"+$Fi lter
+";"+Iif(VarTyp e($What)>8192,J oin($What,','), $What)+";"+
Iif($Scope<>"ba se" AND $Scope<>"onelev el","subtree",$ Scope)

$oCon=CreateObj ect("ADODB.Conn ection")
$oCon.Provider= "ADsDSOObje ct"
$oCon.Propertie s("Encrypt Password").Valu e=1
$oCon.Propertie s("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Propertie s("User ID").Value=$Use r
$oCon.Propertie s("Password").V alue=$Pswd
EndIf
$oCon.Open("Act ive Directory Provider")

$oCMD=CreateObj ect("ADODB.Comm and")
$oCMD.ActiveCon nection=$oCon
$oCMD.CommandTe xt=$sQ
$oCMD.Propertie s("Page Size").Value=10 00
$oCMD.Propertie s("Timeout").Va lue=30
$oCMD.Propertie s("Cache Results").Value =0

If InStr($OrderBy, "distinguishedN ame")
$oRS=CreateObje ct("ADODB.Recor dset")
$oRS.CursorLoca tion=3
$oRS.Sort=$Orde rBy
$oRS.Open($sQ,$ oCon,0,1,1)
Else
If $OrderBy
$oCMD.Propertie s("Sort On").Value=$Ord erBy
EndIf
$oRS=$oCMD.Exec ute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),U bound($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=$a FR
EndFunction
*************** *************** *************** *************** *************** *************** *************** *************** ************

Function fnLDAPQuery(Wha t 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.Connectio n
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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <"onelevel", "subtree", Scope)

oCon = New ADODB.Connectio n
oCon.Provider = "ADsDSOObje ct"
oCon.Properties ("Encrypt Password").Valu e = 1
oCon.Properties ("ADSI Flag").Value = 1
If User And Pswd Then
oCon.Properties ("User ID").Value = User
oCon.Properties ("Password").Va lue = Pswd
End If
oCon.Open("Acti ve Directory Provider")

oCMD = New ADODB.Command
oCMD.ActiveConn ection = oCon
oCMD.CommandTex t = sQ
oCMD.Properties ("Page Size").Value = 1000
oCMD.Properties ("Timeout").Val ue = 30
oCMD.Properties ("Cache Results").Value = 0

If InStr(OrderBy, "distinguishedN ame") Then
oRS = New ADODB.Recordset
oRS.CursorLocat ion = 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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 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 1311

"Ty" <tb*****@lewist ownhospital.org wrote in message
news:22******** *************** ***********@m44 g2000hsc.google groups.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($Wh at,Optional $From,Optional $Filter,Optiona l
$OrderBy,Option al $Scope,
Optional $User,Optional $Pswd)

Dim $oCon,$oCMD,$oR S,$sQ,$aR,$C,$R

$sQ="<"+Iif($Fr om="","LDAP://"+GetObject("LD AP://
rootDSE").Get(" defaultNamingCo ntext"),
$From)+">;"+$Fi lter
+";"+Iif(VarTyp e($What)>8192,J oin($What,','), $What)+";"+
Iif($Scope<>"ba se" AND $Scope<>"onelev el","subtree",$ Scope)

$oCon=CreateObj ect("ADODB.Conn ection")
$oCon.Provider= "ADsDSOObje ct"
$oCon.Propertie s("Encrypt Password").Valu e=1
$oCon.Propertie s("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Propertie s("User ID").Value=$Use r
$oCon.Propertie s("Password").V alue=$Pswd
EndIf
$oCon.Open("Act ive Directory Provider")

$oCMD=CreateObj ect("ADODB.Comm and")
$oCMD.ActiveCon nection=$oCon
$oCMD.CommandTe xt=$sQ
$oCMD.Propertie s("Page Size").Value=10 00
$oCMD.Propertie s("Timeout").Va lue=30
$oCMD.Propertie s("Cache Results").Value =0

If InStr($OrderBy, "distinguishedN ame")
$oRS=CreateObje ct("ADODB.Recor dset")
$oRS.CursorLoca tion=3
$oRS.Sort=$Orde rBy
$oRS.Open($sQ,$ oCon,0,1,1)
Else
If $OrderBy
$oCMD.Propertie s("Sort On").Value=$Ord erBy
EndIf
$oRS=$oCMD.Exec ute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),U bound($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=$a FR
EndFunction
*************** *************** *************** *************** *************** *************** *************** *************** ************

Function fnLDAPQuery(Wha t 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.Connectio n
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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <"onelevel", "subtree", Scope)

oCon = New ADODB.Connectio n
oCon.Provider = "ADsDSOObje ct"
oCon.Properties ("Encrypt Password").Valu e = 1
oCon.Properties ("ADSI Flag").Value = 1
If User And Pswd Then
oCon.Properties ("User ID").Value = User
oCon.Properties ("Password").Va lue = Pswd
End If
oCon.Open("Acti ve Directory Provider")

oCMD = New ADODB.Command
oCMD.ActiveConn ection = oCon
oCMD.CommandTex t = sQ
oCMD.Properties ("Page Size").Value = 1000
oCMD.Properties ("Timeout").Val ue = 30
oCMD.Properties ("Cache Results").Value = 0

If InStr(OrderBy, "distinguishedN ame") Then
oRS = New ADODB.Recordset
oRS.CursorLocat ion = 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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 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.cwrot e:
"Ty" <tbar...@lewist ownhospital.org wrote in message

news:22******** *************** ***********@m44 g2000hsc.google groups.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($Wh at,Optional $From,Optional $Filter,Optiona l
$OrderBy,Option al $Scope,
* *Optional $User,Optional $Pswd)
* *Dim $oCon,$oCMD,$oR S,$sQ,$aR,$C,$R
* *$sQ="<"+Iif($F rom="","LDAP://"+GetObject("LD AP://
rootDSE").Get(" defaultNamingCo ntext"),
* * * *$From)+">;"+$F ilter
+";"+Iif(VarTyp e($What)>8192,J oin($What,','), $What)+";"+
* * * *Iif($Scope<>"b ase" AND $Scope<>"onelev el","subtree",$ Scope)
* *$oCon=CreateOb ject("ADODB.Con nection")
* *$oCon.Provider ="ADsDSOObje ct"
* *$oCon.Properti es("Encrypt Password").Valu e=1
* *$oCon.Properti es("ADSI Flag").Value=1
* *If $User AND $Pswd
* * * *$oCon.Properti es("User ID").Value=$Use r
* * * *$oCon.Properti es("Password"). Value=$Pswd
* *EndIf
* *$oCon.Open("Ac tive Directory Provider")
* *$oCMD=CreateOb ject("ADODB.Com mand")
* *$oCMD.ActiveCo nnection=$oCon
* *$oCMD.CommandT ext=$sQ
* *$oCMD.Properti es("Page Size").Value=10 00
* *$oCMD.Properti es("Timeout").V alue=30
* *$oCMD.Properti es("Cache Results").Value =0
* *If InStr($OrderBy, "distinguishedN ame")
* * * *$oRS=CreateObj ect("ADODB.Reco rdset")
* * * *$oRS.CursorLoc ation=3
* * * *$oRS.Sort=$Ord erBy
* * * *$oRS.Open($sQ, $oCon,0,1,1)
* *Else
* * * *If $OrderBy
* * * * * *$oCMD.Properti es("Sort On").Value=$Ord erBy
* * * *EndIf
* * * *$oRS=$oCMD.Exe cute
* *EndIf
* *If @ERROR Exit @ERROR EndIf
* *If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf
* *$aR = $oRS.GetRows()
* *Dim $aFR[Ubound($aR,2),U bound($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(Wha t 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.Connectio n
* * * *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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 8192, Join(What, ","), What) & ";" & IIf(Scope <>
"base" And Scope <"onelevel", "subtree", Scope)
* * * *oCon = New ADODB.Connectio n
* * * *oCon.Provider = "ADsDSOObje ct"
* * * *oCon.Propertie s("Encrypt Password").Valu e = 1
* * * *oCon.Propertie s("ADSI Flag").Value = 1
* * * *If User And Pswd Then
* * * * * *oCon.Propertie s("User ID").Value = User
* * * * * *oCon.Propertie s("Password").V alue = Pswd
* * * *End If
* * * *oCon.Open("Act ive Directory Provider")
* * * *oCMD = New ADODB.Command
* * * *oCMD.ActiveCon nection = oCon
* * * *oCMD.CommandTe xt = sQ
* * * *oCMD.Propertie s("Page Size").Value = 1000
* * * *oCMD.Propertie s("Timeout").Va lue = 30
* * * *oCMD.Propertie s("Cache Results").Value = 0
* * * *If InStr(OrderBy, "distinguishedN ame") Then
* * * * * *oRS = New ADODB.Recordset
* * * * * *oRS.CursorLoca tion = 3
* * * * * *oRS.Sort = OrderBy
* * * * * *oRS.Open(sQ, oCon, 0, 1, 1)
* * * *Else
* * * * * *If OrderBy Then
* * * * * * * *oCMD.Propertie s("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(" defaultNamingCo ntext"), From) & ">;" & Filter & ";" &
IIf(VarType(Wha t) 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
3199
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. However when you retrieve these values into a dataset and ToString() them
2
6178
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 However, It gave me such error when I tried to make db connection via command prompt(windows)
40
517
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. However when you retrieve these values into a dataset and ToString() them
1
3702
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
1
3654
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 right. The code works, but I'm not familiar with the codecvt, and I don't know my way is the right way to do the job. Could you help me to review the code? This function try to convert a wide string to a MBCS in the loc's charset. I hardcode...
0
8011
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8503
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8488
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8160
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8358
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5482
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3972
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1339
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.