Hi all,
I have some VBScript code that I am trying to port over to VB.NET. I am
receiving an error "Cast from type 'Field' to type 'String' is not valid."
when calling the MapLegacyExchangeDN method. I'm thinking that the parameter
sDirName isn't being properly passed to the function. The same code works in
VBScript. Can someone help, this should be an easy one but I cant figure it
out! And yes, I am a VB.NET newbie!
Thanks.
Martin
Code:
Dim sLDAPServer As String = "server.domain.local"
Dim sDirName As String = "/o=DOMAIN/ou=First Administrative
Group/cn=Recipients/cn=shmoej"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim objSession
Dim objFolder
Dim pubContactItems
Dim sEmailName
Dim sDirName
sDirName = MapLegacyExchangeDN(sDirName)
sDirName = RetrieveSMTP(sDirName)
sEmailName = sDirName
MsgBox("E-mail: " & sEmailName)
Error_Handler:
If Err.Number <> 0 Then
MsgBox("Error number: " & (Err.Number) & ", " & Err.Description)
Err.Clear()
Else : MsgBox("Everything OK")
End If
End Sub
Function RetrieveSMTP(ByVal sDirName As String)
Dim objMailbox As Object
Dim sMemberAddr
objMailbox = GetObject("LDAP://" & sLDAPServer & "/" & sDirName)
If Err.Number = 0 Then
sMemberAddr = objMailbox.GetEx("mail")(0)
If Err.Number = 0 Then
End If
End If
RetrieveSMTP = sMemberAddr
End Function
Function MapLegacyExchangeDN(ByVal sDirName As String)
Dim ADOconn
Dim strADOQueryString
Dim RS
Dim sResult
Dim bShowAll
ADOconn = CreateObject("ADODB.Connection")
ADOconn.Provider = "ADSDSOObject"
ADOconn.Open("Active Directory Provider")
strADOQueryString = "<LDAP://" & sLDAPServer & ">;(legacyExchangeDN=*" &
sDirName & "*);distinguishedName;subtree"
On Error Resume Next
RS = ADOconn.Execute(strADOQueryString)
If Err.Number <> 0 Then
MsgBox("Error searching for legacyExchangeDN " & Err.Number & " " &
Err.Description)
End If
sResult = ""
If Not RS.EOF Then
If RS.recordcount > 1 Then
bShowAll = True
Else
bShowAll = False
End If
While Not RS.EOF
sResult = RS.Fields(0)
RS.MoveNext()
End While
End If
RS.Close()
RS = Nothing
ADOconn = Nothing
MapLegacyExchangeDN = sResult
End Function 3 1792
Martin,
You need to get out of the habit of using default properties.
Change sResult = RS.Fields(0) to sResult = RS.Fields(0).Value
and you should be in business.
--
Al Reid
--
Al Reid
"Martin" <bm******@email.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... Hi all,
I have some VBScript code that I am trying to port over to VB.NET. I am receiving an error "Cast from type 'Field' to type 'String' is not valid." when calling the MapLegacyExchangeDN method. I'm thinking that the parameter sDirName isn't being properly passed to the function. The same code works in VBScript. Can someone help, this should be an easy one but I cant figure it out! And yes, I am a VB.NET newbie!
Thanks.
Martin
Code:
Dim sLDAPServer As String = "server.domain.local" Dim sDirName As String = "/o=DOMAIN/ou=First Administrative Group/cn=Recipients/cn=shmoej" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objSession Dim objFolder Dim pubContactItems Dim sEmailName Dim sDirName sDirName = MapLegacyExchangeDN(sDirName) sDirName = RetrieveSMTP(sDirName) sEmailName = sDirName MsgBox("E-mail: " & sEmailName) Error_Handler: If Err.Number <> 0 Then MsgBox("Error number: " & (Err.Number) & ", " & Err.Description) Err.Clear() Else : MsgBox("Everything OK") End If End Sub Function RetrieveSMTP(ByVal sDirName As String) Dim objMailbox As Object Dim sMemberAddr objMailbox = GetObject("LDAP://" & sLDAPServer & "/" & sDirName) If Err.Number = 0 Then sMemberAddr = objMailbox.GetEx("mail")(0) If Err.Number = 0 Then End If End If RetrieveSMTP = sMemberAddr End Function Function MapLegacyExchangeDN(ByVal sDirName As String) Dim ADOconn Dim strADOQueryString Dim RS Dim sResult Dim bShowAll ADOconn = CreateObject("ADODB.Connection") ADOconn.Provider = "ADSDSOObject" ADOconn.Open("Active Directory Provider") strADOQueryString = "<LDAP://" & sLDAPServer & ">;(legacyExchangeDN=*" & sDirName & "*);distinguishedName;subtree" On Error Resume Next RS = ADOconn.Execute(strADOQueryString) If Err.Number <> 0 Then MsgBox("Error searching for legacyExchangeDN " & Err.Number & " " & Err.Description) End If sResult = "" If Not RS.EOF Then If RS.recordcount > 1 Then bShowAll = True Else bShowAll = False End If While Not RS.EOF sResult = RS.Fields(0) RS.MoveNext() End While End If RS.Close() RS = Nothing ADOconn = Nothing MapLegacyExchangeDN = sResult End Function
Al,
Thanks for the quick reply and help! It works now! I cant believe it was
something that small.
-Martin
"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:uH**************@TK2MSFTNGP11.phx.gbl... Martin,
You need to get out of the habit of using default properties.
Change sResult = RS.Fields(0) to sResult = RS.Fields(0).Value and you should be in business.
-- Al Reid
-- Al Reid
"Martin" <bm******@email.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Hi all,
I have some VBScript code that I am trying to port over to VB.NET. I am receiving an error "Cast from type 'Field' to type 'String' is not
valid." when calling the MapLegacyExchangeDN method. I'm thinking that the
parameter sDirName isn't being properly passed to the function. The same code
works in VBScript. Can someone help, this should be an easy one but I cant figure
it out! And yes, I am a VB.NET newbie!
Thanks.
Martin
Code:
Dim sLDAPServer As String = "server.domain.local" Dim sDirName As String = "/o=DOMAIN/ou=First Administrative Group/cn=Recipients/cn=shmoej" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objSession Dim objFolder Dim pubContactItems Dim sEmailName Dim sDirName sDirName = MapLegacyExchangeDN(sDirName) sDirName = RetrieveSMTP(sDirName) sEmailName = sDirName MsgBox("E-mail: " & sEmailName) Error_Handler: If Err.Number <> 0 Then MsgBox("Error number: " & (Err.Number) & ", " & Err.Description) Err.Clear() Else : MsgBox("Everything OK") End If End Sub Function RetrieveSMTP(ByVal sDirName As String) Dim objMailbox As Object Dim sMemberAddr objMailbox = GetObject("LDAP://" & sLDAPServer & "/" & sDirName) If Err.Number = 0 Then sMemberAddr = objMailbox.GetEx("mail")(0) If Err.Number = 0 Then End If End If RetrieveSMTP = sMemberAddr End Function Function MapLegacyExchangeDN(ByVal sDirName As String) Dim ADOconn Dim strADOQueryString Dim RS Dim sResult Dim bShowAll ADOconn = CreateObject("ADODB.Connection") ADOconn.Provider = "ADSDSOObject" ADOconn.Open("Active Directory Provider") strADOQueryString = "<LDAP://" & sLDAPServer & ">;(legacyExchangeDN=*" & sDirName & "*);distinguishedName;subtree" On Error Resume Next RS = ADOconn.Execute(strADOQueryString) If Err.Number <> 0 Then MsgBox("Error searching for legacyExchangeDN " & Err.Number & " " & Err.Description) End If sResult = "" If Not RS.EOF Then If RS.recordcount > 1 Then bShowAll = True Else bShowAll = False End If While Not RS.EOF sResult = RS.Fields(0) RS.MoveNext() End While End If RS.Close() RS = Nothing ADOconn = Nothing MapLegacyExchangeDN = sResult End Function
Martin,
No problem. It's often the small stuff that bites you.<g>
--
Al Reid
"Martin" <bm******@email.com> wrote in message news:O7**************@TK2MSFTNGP11.phx.gbl... Al,
Thanks for the quick reply and help! It works now! I cant believe it was something that small.
-Martin
"Al Reid" <ar*****@reidDASHhome.com> wrote in message news:uH**************@TK2MSFTNGP11.phx.gbl... Martin,
You need to get out of the habit of using default properties.
Change sResult = RS.Fields(0) to sResult = RS.Fields(0).Value and you should be in business.
-- Al Reid
-- Al Reid
"Martin" <bm******@email.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... Hi all,
I have some VBScript code that I am trying to port over to VB.NET. I am receiving an error "Cast from type 'Field' to type 'String' is not valid." when calling the MapLegacyExchangeDN method. I'm thinking that the parameter sDirName isn't being properly passed to the function. The same code works in VBScript. Can someone help, this should be an easy one but I cant figure it out! And yes, I am a VB.NET newbie!
Thanks.
Martin
Code:
Dim sLDAPServer As String = "server.domain.local" Dim sDirName As String = "/o=DOMAIN/ou=First Administrative Group/cn=Recipients/cn=shmoej" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objSession Dim objFolder Dim pubContactItems Dim sEmailName Dim sDirName sDirName = MapLegacyExchangeDN(sDirName) sDirName = RetrieveSMTP(sDirName) sEmailName = sDirName MsgBox("E-mail: " & sEmailName) Error_Handler: If Err.Number <> 0 Then MsgBox("Error number: " & (Err.Number) & ", " & Err.Description) Err.Clear() Else : MsgBox("Everything OK") End If End Sub Function RetrieveSMTP(ByVal sDirName As String) Dim objMailbox As Object Dim sMemberAddr objMailbox = GetObject("LDAP://" & sLDAPServer & "/" & sDirName) If Err.Number = 0 Then sMemberAddr = objMailbox.GetEx("mail")(0) If Err.Number = 0 Then End If End If RetrieveSMTP = sMemberAddr End Function Function MapLegacyExchangeDN(ByVal sDirName As String) Dim ADOconn Dim strADOQueryString Dim RS Dim sResult Dim bShowAll ADOconn = CreateObject("ADODB.Connection") ADOconn.Provider = "ADSDSOObject" ADOconn.Open("Active Directory Provider") strADOQueryString = "<LDAP://" & sLDAPServer & ">;(legacyExchangeDN=*" & sDirName & "*);distinguishedName;subtree" On Error Resume Next RS = ADOconn.Execute(strADOQueryString) If Err.Number <> 0 Then MsgBox("Error searching for legacyExchangeDN " & Err.Number & " " & Err.Description) End If sResult = "" If Not RS.EOF Then If RS.recordcount > 1 Then bShowAll = True Else bShowAll = False End If While Not RS.EOF sResult = RS.Fields(0) RS.MoveNext() End While End If RS.Close() RS = Nothing ADOconn = Nothing MapLegacyExchangeDN = sResult End Function
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Beach Potato |
last post by:
Dear Y'all:
I'm about to start porting a big old project written in anscient version
of Delphi to something more stable, robust, supportable and maybe even
portable. Since I haven't seriously...
|
by: Anand |
last post by:
Hi
Are there any tools that would help in porting code from
Pyton 2.3 to 2.4 ? I have gone through the whatsnew documents
and created a document comparing Python 2.4 to 2.3. But so far
has not...
|
by: Ryan Liu |
last post by:
Hi All,
Now I am porting CC to GCC and I have some problems.
Would you mind tell me some document which have some description how to port
CC to GCC ??
Thank you very much.
Ryan
|
by: Kenton Groombridge |
last post by:
Hi,
I previous posted this in a gcc and g++ groups since that is the
compiler I am working with, but I didn't get any response.
Hopefully these are the right groups for this question. I am...
|
by: Jed |
last post by:
Hello to all!
I have a couple of projects I intend starting on, and was wondering if
someone here could make a suggestion for a good compiler and development
environment.
My goals are as...
|
by: Chris Travers |
last post by:
Hi all;
A few years ago, I set about porting a PHP application from MySQL to
PostgreSQL, after realizing that MySQL wasn't going to be able to handle it.
In order to do this, I built a light,...
|
by: Tone |
last post by:
I've written a large suite of ANSI C routines for a virtual hand-held
device. A hardware manufacturer with whom we wish to do business
prefers C#.
My understanding of C# is somewhat limited. I...
|
by: Bill |
last post by:
Does anyone know how to fix this problem? On form submittal I'm getting the
following error in Visual Studio 2005:
The state information is invalid for this page and might be corrupted....
|
by: Ian |
last post by:
I would like to hear from others who have considered and/or ported code from
traditional C++ to C++/CLI.
The class library I am considering porting to C++/CLI was written in
traditional C++ with...
|
by: subramanian100in |
last post by:
Is there any difference between porting and migrating.
Kindly explain
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
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,...
|
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$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |