I had to convert some C# code to VB and I am getting the following error: "Value of type 'Double' cannot be converted to 'Long'"
I am getting it on the following code:
Private Shared Function SignVals(key As String, username As String, ikey As String, prefix As String, expire As Int64, current_time As DateTime) As String
Dim ts As Int64 = DirectCast((current_time - New DateTime(1970, 1, 1)).TotalSeconds, Int64)
expire = ts + expire
Dim val As String = (Convert.ToString(username & Convert.ToString("|")) & ikey) + "|" + expire.ToString()
Dim cookie As String = Convert.ToString(prefix & Convert.ToString("|")) & Encode64(val)
Dim sig As String = HmacSign(key, cookie)
Return Convert.ToString(cookie & Convert.ToString("|")) & sig
End Function
You might try simply using the Convert.ToInt64 method as seen below and revising over your Convert.ToString() methods :
Private Shared Function SignVals(key As String, username As String, ikey As String, prefix As String, expire As Int64, current_time As DateTime) As String
Dim ts As Int64 = Convert.ToInt64((current_time - New DateTime(1970, 1, 1)).TotalSeconds)
expire = ts + expire
Dim val As String = username & "|" & ikey & "|" & expire.ToString()
Dim cookie As String = prefix & "|" & Encode64(val)
Dim sig As String = HmacSign(key, cookie)
Return cookie & "|" & sig
End Function
Member
115 Points
582 Posts
C# to VB Conversion
Oct 22, 2013 01:13 PM|mattcase|LINK
Hi,
I had to convert some C# code to VB and I am getting the following error: "Value of type 'Double' cannot be converted to 'Long'"
I am getting it on the following code:
Does anyone know how to fix this?
Thanks.
C vb error Convert
Participant
1001 Points
417 Posts
Re: C# to VB Conversion
Oct 22, 2013 01:25 PM|stockcer|LINK
Did you try to use one of these?
http://blog.arvixe.com/converting-c-to-vb-and-back-again-2/
C vb error Convert
James River Webs, Inc.
Member
115 Points
582 Posts
Re: C# to VB Conversion
Oct 22, 2013 01:39 PM|mattcase|LINK
Yes, I used the one from Telerik.
C vb error Convert
All-Star
114593 Points
18503 Posts
MVP
Re: C# to VB Conversion
Oct 22, 2013 01:40 PM|Rion Williams|LINK
You might try simply using the Convert.ToInt64 method as seen below and revising over your Convert.ToString() methods :
C vb error Convert
Member
115 Points
582 Posts
Re: C# to VB Conversion
Oct 22, 2013 01:50 PM|mattcase|LINK
Perfect! Thanks!
C vb error Convert