By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

issue when converting C#.net code into vb.net

P: n/a
Hi All,

I am facing problem when i am converting C#.net code(Delegate concept)
into vb.net. I am unable to do that . Can someone help me to solve the
problem. I am providing my C#.net code.

==================================my code is :-
======================================
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapperGetMembers(bool
returnAllApprovedUsers, bool returnAllNotApprovedUsers,
string usernameToFind, string sortData)
{

List<MembershipUserWrappermemberList = new
List<MembershipUserWrapper>();

// See if we are looking for just one user
if (usernameToFind != null)
{
MembershipUser mu =
Membership.GetUser(usernameToFind);
if (mu != null)
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
else
{
MembershipUserCollection muc =
Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
if ((returnAllApprovedUsers == true &&
mu.IsApproved == true) ||
(returnAllNotApprovedUsers == true &&
mu.IsApproved == false))
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}

if (sortData == null)
{
sortData = "UserName";
}
if (sortData.Length == 0)
{
sortData = "UserName";
}
string sortDataBase = sortData;
string descString = " DESC";
if (sortData.EndsWith(descString))
{
sortDataBase = sortData.Substring(0,
sortData.Length - descString.Length);
}

Comparison<MembershipUserWrappercomparison = null;

switch (sortDataBase)
{
case "UserName":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
case "Email":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
if (lhs.Email == null | rhs.Email ==
null)
{
return 0;
}
else
{
return
lhs.Email.CompareTo(rhs.Email);
}
}
);
break;
case "CreationDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);
break;
case "IsApproved":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsApproved.CompareTo(rhs.IsApproved);
}
);
break;
case "IsOnline":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsOnline.CompareTo(rhs.IsOnline);
}
);
break;
case "LastLoginDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);
}
);
break;
default:
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
}

if (sortData.EndsWith("DESC"))
{
memberList.Sort(comparison);
memberList.Reverse();
}
else
{
memberList.Sort(comparison);
}

}

return memberList;

}
====================================C#.net code
end==================================

now i want this part of code into vb.net code , can some one please
provide me the solution.
I had tried writing myself C#.net code into vb.net code but unable to
acheive correct vb.net code.I had used some conversion tool also from
developer fusion site but it is showing error that is some different
kind of error.Please provide me the vb.net code.
it's urgent

Thanks in advance
Dhananjay
Jan 29 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The following conversion should be pretty close - however, Instant VB can't
determine the return types of the extracted methods (since VB doesn't have
anonymous methods - see the 'delegate' keyword in your original code), so it
uses 'Object' - you'll have to adjust these:

<DataObjectMethod(DataObjectMethodType.Select, False)_
Public Shared Function GetMembers(ByVal returnAllApprovedUsers As Boolean,
ByVal returnAllNotApprovedUsers As Boolean, ByVal usernameToFind As String,
ByVal sortData As String) As List(Of MembershipUserWrapper)

Dim memberList As List(Of MembershipUserWrapper) = New List(Of
MembershipUserWrapper)()

' See if we are looking for just one user
If usernameToFind IsNot Nothing Then
Dim mu As MembershipUser = Membership.GetUser(usernameToFind)
If mu IsNot Nothing Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Else
Dim muc As MembershipUserCollection = Membership.GetAllUsers()
For Each mu As MembershipUser In muc
If (returnAllApprovedUsers = True AndAlso mu.IsApproved = True) OrElse
(returnAllNotApprovedUsers = True AndAlso mu.IsApproved = False) Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Next mu

If sortData Is Nothing Then
sortData = "UserName"
End If
If sortData.Length = 0 Then
sortData = "UserName"
End If
Dim sortDataBase As String = sortData
Dim descString As String = " DESC"
If sortData.EndsWith(descString) Then
sortDataBase = sortData.Substring(0, sortData.Length - descString.Length)
End If

Dim comparison As Comparison(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase
Case "UserName"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)
Case "Email"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)
Case "CreationDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)
Case "IsApproved"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)
Case "IsOnline"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)
Case "LastLoginDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)
Case Else
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)
End Select

If sortData.EndsWith("DESC") Then
memberList.Sort(comparison)
memberList.Reverse()
Else
memberList.Sort(comparison)
End If

End If
Return memberList
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod1(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod2(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
If lhs.Email Is Nothing Or rhs.Email Is Nothing Then
Return 0
Else
Return lhs.Email.CompareTo(rhs.Email)
End If
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod3(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.CreationDate.CompareTo(rhs.CreationDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod4(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsApproved.CompareTo(rhs.IsApproved)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod5(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsOnline.CompareTo(rhs.IsOnline)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod6(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod7(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI
"Dhananjay" wrote:
Hi All,

I am facing problem when i am converting C#.net code(Delegate concept)
into vb.net. I am unable to do that . Can someone help me to solve the
problem. I am providing my C#.net code.

==================================my code is :-
======================================
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapperGetMembers(bool
returnAllApprovedUsers, bool returnAllNotApprovedUsers,
string usernameToFind, string sortData)
{

List<MembershipUserWrappermemberList = new
List<MembershipUserWrapper>();

// See if we are looking for just one user
if (usernameToFind != null)
{
MembershipUser mu =
Membership.GetUser(usernameToFind);
if (mu != null)
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
else
{
MembershipUserCollection muc =
Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
if ((returnAllApprovedUsers == true &&
mu.IsApproved == true) ||
(returnAllNotApprovedUsers == true &&
mu.IsApproved == false))
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}

if (sortData == null)
{
sortData = "UserName";
}
if (sortData.Length == 0)
{
sortData = "UserName";
}
string sortDataBase = sortData;
string descString = " DESC";
if (sortData.EndsWith(descString))
{
sortDataBase = sortData.Substring(0,
sortData.Length - descString.Length);
}

Comparison<MembershipUserWrappercomparison = null;

switch (sortDataBase)
{
case "UserName":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
case "Email":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
if (lhs.Email == null | rhs.Email ==
null)
{
return 0;
}
else
{
return
lhs.Email.CompareTo(rhs.Email);
}
}
);
break;
case "CreationDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);
break;
case "IsApproved":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsApproved.CompareTo(rhs.IsApproved);
}
);
break;
case "IsOnline":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsOnline.CompareTo(rhs.IsOnline);
}
);
break;
case "LastLoginDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.LastLoginDate.CompareTo(rhs.LastLoginDate);
}
);
break;
default:
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
}

if (sortData.EndsWith("DESC"))
{
memberList.Sort(comparison);
memberList.Reverse();
}
else
{
memberList.Sort(comparison);
}

}

return memberList;

}
====================================C#.net code
end==================================

now i want this part of code into vb.net code , can some one please
provide me the solution.
I had tried writing myself C#.net code into vb.net code but unable to
acheive correct vb.net code.I had used some conversion tool also from
developer fusion site but it is showing error that is some different
kind of error.Please provide me the vb.net code.
it's urgent

Thanks in advance
Dhananjay
Jan 29 '08 #2

P: n/a
On Jan 29, 9:52 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The following conversion should be pretty close - however, Instant VB can't
determine the return types of the extracted methods (since VB doesn't have
anonymous methods - see the 'delegate' keyword in your original code), so it
uses 'Object' - you'll have to adjust these:

<DataObjectMethod(DataObjectMethodType.Select, False)_
Public Shared Function GetMembers(ByVal returnAllApprovedUsers As Boolean,
ByVal returnAllNotApprovedUsers As Boolean, ByVal usernameToFind As String,
ByVal sortData As String) As List(Of MembershipUserWrapper)

Dim memberList As List(Of MembershipUserWrapper) = New List(Of
MembershipUserWrapper)()

' See if we are looking for just one user
If usernameToFind IsNot Nothing Then
Dim mu As MembershipUser = Membership.GetUser(usernameToFind)
If mu IsNot Nothing Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Else
Dim muc As MembershipUserCollection = Membership.GetAllUsers()
For Each mu As MembershipUser In muc
If (returnAllApprovedUsers = True AndAlso mu.IsApproved = True) OrElse
(returnAllNotApprovedUsers = True AndAlso mu.IsApproved = False) Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Next mu

If sortData Is Nothing Then
sortData = "UserName"
End If
If sortData.Length = 0 Then
sortData = "UserName"
End If

Dim sortDataBase As String = sortData
Dim descString As String = " DESC"
If sortData.EndsWith(descString) Then
sortDataBase = sortData.Substring(0, sortData.Length - descString.Length)
End If

Dim comparison As Comparison(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase
Case "UserName"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)
Case "Email"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)
Case "CreationDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)
Case "IsApproved"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)
Case "IsOnline"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)
Case "LastLoginDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)
Case Else
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)
End Select

If sortData.EndsWith("DESC") Then
memberList.Sort(comparison)
memberList.Reverse()
Else
memberList.Sort(comparison)
End If

End If
Return memberList
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod1(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod2(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
If lhs.Email Is Nothing Or rhs.Email Is Nothing Then
Return 0
Else
Return lhs.Email.CompareTo(rhs.Email)
End If
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod3(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.CreationDate.CompareTo(rhs.CreationDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod4(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsApproved.CompareTo(rhs.IsApproved)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod5(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsOnline.CompareTo(rhs.IsOnline)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod6(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod7(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function

--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI

"Dhananjay" wrote:
Hi All,
I am facing problem when i am converting C#.net code(Delegate concept)
into vb.net. I am unable to do that . Can someone help me to solve the
problem. I am providing my C#.net code.
==================================my code is :-
======================================
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapperGetMembers(bool
returnAllApprovedUsers, bool returnAllNotApprovedUsers,
string usernameToFind, string sortData)
{
List<MembershipUserWrappermemberList = new
List<MembershipUserWrapper>();
// See if we are looking for just one user
if (usernameToFind != null)
{
MembershipUser mu =
Membership.GetUser(usernameToFind);
if (mu != null)
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
else
{
MembershipUserCollection muc =
Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
if ((returnAllApprovedUsers == true &&
mu.IsApproved == true) ||
(returnAllNotApprovedUsers == true &&
mu.IsApproved == false))
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
if (sortData == null)
{
sortData = "UserName";
}
if (sortData.Length == 0)
{
sortData = "UserName";
}
string sortDataBase = sortData;
string descString = " DESC";
if (sortData.EndsWith(descString))
{
sortDataBase = sortData.Substring(0,
sortData.Length - descString.Length);
}
Comparison<MembershipUserWrappercomparison = null;
switch (sortDataBase)
{
case "UserName":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
case "Email":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
if (lhs.Email == null | rhs.Email ==
null)
{
return 0;
}
else
{
return
lhs.Email.CompareTo(rhs.Email);
}
}
);
break;
case "CreationDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);
break;
case "IsApproved":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsApproved.CompareTo(rhs.IsApproved);
}
);
break;
case "IsOnline":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsOnline.CompareTo(rhs.IsOnline);
}
);
break;
case "LastLoginDate":
comparison = new

...

read more


Hi David,

First of all thanks a lot for help.
After copying the vb.net converted code( which i required) given by
you, I have got an error (Address Of AnonymousMethod) which says ''
method 'private shared function AnonymousMethod7(lhs as
membershipUtilities.membershipUserWrapper, rhs as
membershipUtilities.membershipUserWrapper ) As Object' doesn't have
same signature As delegate 'Delegate Function Comparision(Of T) (x as
membershipUserWrapper, y as membershipUserWrapper) As Integer ''

How do i proceed please guide me as earliest as possible
Thanks in advance
Dhananjay
Jan 29 '08 #3

P: n/a
Just change the signature of the converted method to match the delegate.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI
"Dhananjay" wrote:
On Jan 29, 9:52 pm, David Anton <DavidAn...@discussions.microsoft.com>
wrote:
The following conversion should be pretty close - however, Instant VB can't
determine the return types of the extracted methods (since VB doesn't have
anonymous methods - see the 'delegate' keyword in your original code), so it
uses 'Object' - you'll have to adjust these:

<DataObjectMethod(DataObjectMethodType.Select, False)_
Public Shared Function GetMembers(ByVal returnAllApprovedUsers As Boolean,
ByVal returnAllNotApprovedUsers As Boolean, ByVal usernameToFind As String,
ByVal sortData As String) As List(Of MembershipUserWrapper)

Dim memberList As List(Of MembershipUserWrapper) = New List(Of
MembershipUserWrapper)()

' See if we are looking for just one user
If usernameToFind IsNot Nothing Then
Dim mu As MembershipUser = Membership.GetUser(usernameToFind)
If mu IsNot Nothing Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Else
Dim muc As MembershipUserCollection = Membership.GetAllUsers()
For Each mu As MembershipUser In muc
If (returnAllApprovedUsers = True AndAlso mu.IsApproved = True) OrElse
(returnAllNotApprovedUsers = True AndAlso mu.IsApproved = False) Then
Dim md As New MembershipUserWrapper(mu)
memberList.Add(md)
End If
Next mu

If sortData Is Nothing Then
sortData = "UserName"
End If
If sortData.Length = 0 Then
sortData = "UserName"
End If

Dim sortDataBase As String = sortData
Dim descString As String = " DESC"
If sortData.EndsWith(descString) Then
sortDataBase = sortData.Substring(0, sortData.Length - descString.Length)
End If

Dim comparison As Comparison(Of MembershipUserWrapper) = Nothing

Select Case sortDataBase
Case "UserName"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod1)
Case "Email"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod2)
Case "CreationDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod3)
Case "IsApproved"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod4)
Case "IsOnline"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod5)
Case "LastLoginDate"
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod6)
Case Else
comparison = New Comparison(Of MembershipUserWrapper)(AddressOf
AnonymousMethod7)
End Select

If sortData.EndsWith("DESC") Then
memberList.Sort(comparison)
memberList.Reverse()
Else
memberList.Sort(comparison)
End If

End If
Return memberList
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod1(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod2(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
If lhs.Email Is Nothing Or rhs.Email Is Nothing Then
Return 0
Else
Return lhs.Email.CompareTo(rhs.Email)
End If
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod3(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.CreationDate.CompareTo(rhs.CreationDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod4(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsApproved.CompareTo(rhs.IsApproved)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod5(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.IsOnline.CompareTo(rhs.IsOnline)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod6(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.LastLoginDate.CompareTo(rhs.LastLoginDate)
End Function
'TODO: INSTANT VB TODO TASK: The return type of this anonymous method
could not be determined by Instant VB:
Private Shared Function AnonymousMethod7(ByVal lhs As
MembershipUserWrapper, ByVal rhs As MembershipUserWrapper) As Object
Return lhs.UserName.CompareTo(rhs.UserName)
End Function

--http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++ VB Edition: VB to C++/CLI
Instant C++ C# Edition: C# to C++/CLI

"Dhananjay" wrote:
Hi All,
I am facing problem when i am converting C#.net code(Delegate concept)
into vb.net. I am unable to do that . Can someone help me to solve the
problem. I am providing my C#.net code.
==================================my code is :-
======================================
[DataObjectMethod(DataObjectMethodType.Select, false)]
static public List<MembershipUserWrapperGetMembers(bool
returnAllApprovedUsers, bool returnAllNotApprovedUsers,
string usernameToFind, string sortData)
{
List<MembershipUserWrappermemberList = new
List<MembershipUserWrapper>();
// See if we are looking for just one user
if (usernameToFind != null)
{
MembershipUser mu =
Membership.GetUser(usernameToFind);
if (mu != null)
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
else
{
MembershipUserCollection muc =
Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
if ((returnAllApprovedUsers == true &&
mu.IsApproved == true) ||
(returnAllNotApprovedUsers == true &&
mu.IsApproved == false))
{
MembershipUserWrapper md = new
MembershipUserWrapper(mu);
memberList.Add(md);
}
}
if (sortData == null)
{
sortData = "UserName";
}
if (sortData.Length == 0)
{
sortData = "UserName";
}
string sortDataBase = sortData;
string descString = " DESC";
if (sortData.EndsWith(descString))
{
sortDataBase = sortData.Substring(0,
sortData.Length - descString.Length);
}
Comparison<MembershipUserWrappercomparison = null;
switch (sortDataBase)
{
case "UserName":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.UserName.CompareTo(rhs.UserName);
}
);
break;
case "Email":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
if (lhs.Email == null | rhs.Email ==
null)
{
return 0;
}
else
{
return
lhs.Email.CompareTo(rhs.Email);
}
}
);
break;
case "CreationDate":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.CreationDate.CompareTo(rhs.CreationDate);
}
);
break;
case "IsApproved":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsApproved.CompareTo(rhs.IsApproved);
}
);
break;
case "IsOnline":
comparison = new
Comparison<MembershipUserWrapper>(
delegate(MembershipUserWrapper lhs,
MembershipUserWrapper rhs)
{
return
lhs.IsOnline.CompareTo(rhs.IsOnline);
}
);
break;
case "LastLoginDate":
comparison = new
...

read more »

Hi David,

First of all thanks a lot for help.
After copying the vb.net converted code( which i required) given by
you, I have got an error (Address Of AnonymousMethod) which says ''
method 'private shared function AnonymousMethod7(lhs as
membershipUtilities.membershipUserWrapper, rhs as
membershipUtilities.membershipUserWrapper ) As Object' doesn't have
same signature As delegate 'Delegate Function Comparision(Of T) (x as
membershipUserWrapper, y as membershipUserWrapper) As Integer ''

How do i proceed please guide me as earliest as possible
Thanks in advance
Dhananjay
Jan 29 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.