Click here to Skip to main content
15,916,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please i need help on this c# code.I am trying to convert it to vb.net but it is giving error.Please help a noob out.

Quote:
public const string CartId = "TailSpinSpyWorks_CartID";

Quote:
public String GetShoppingCartId()
{
if (Session[CartId] == null)
{
Session[CartId] = System.Web.HttpContext.Current.Request.IsAuthenticated ?
User.Identity.Name : Guid.NewGuid().ToString();
}
return Session[CartId].ToString();
}
Posted
Comments
[no name] 3-May-13 7:45am    
And we are supposed to guess which error you are getting out of the hundreds that it could be?
CPallini 3-May-13 7:51am    
Not exactly: we are also supposed to guess his conversion code.
[no name] 3-May-13 7:55am    
Or both.

1 solution

I Generally use DeveloperFusion to do small converts like that: http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
It suggests
VB
Public Const CartId As String = "TailSpinSpyWorks_CartID"
And
VB
Public Function GetShoppingCartId() As [String]
	If Session(CartId) Is Nothing Then
		Session(CartId) = If(System.Web.HttpContext.Current.Request.IsAuthenticated, User.Identity.Name, Guid.NewGuid().ToString())
	End If
	Return Session(CartId).ToString()
End Function
Which look pretty reasonable.
 
Share this answer
 
Comments
jamiebones 3-May-13 7:59am    
The error is it underlined the comma after isAuthenticated saying ')' expected.Don't know what that means
OriginalGriff 3-May-13 8:13am    
It means "Developerfusion missed an 'I':
Try
Session(CartId) = IIf(System.Web.HttpContext.Current.Request.IsAuthenticated,
instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900