A
Atara
In my apllication I use the following code:
'-- My Code:
Public Shared Function strDate2Date(ByVal strDate As String) As
System.DateTime
Dim isOk As Boolean = False
If (strDate Is Nothing) Then
isOk = False
ElseIf Not (strDate.Length() = 6) Then
isOk = False
Else
isOk = True
Dim yyyy As Integer = CInt(strDate.Substring(0, 2)) + 2000
Dim mm As Integer = CInt(strDate.Substring(2, 2))
Dim dd As Integer = CInt(strDate.Substring(4, 2))
Return (New System.DateTime(yyyy, mm, dd))
End If
Return Nothing
End Function
dim myDateCreated1 As System.DateTime = strDate2Date("020801") ' 1
Aug 2002
dim myDateCreated2 As System.DateTime = strDate2Date("040404") ' 4
Apr 2004
dim myDateCreated3 As System.DateTime = strDate2Date("040420") ' 20
Apr 2004
dim myDateCreated4 As System.DateTime = strDate2Date("041104") ' 4
Nov 2004
'-- Code till here.
On of my Italian client got the exception:
'-- Exception:
System.ArgumentException: The currency separator information specified
in the NumberFormatInfo is ambiguous for parsing.
at Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String
Value, NumberFormatInfo NumberFormat)
at
Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(String
Value)
at myassembly.strDate2Date(String strDate)
'-- Exception till here.
When googling I understood that the VB compiler compiles CInt into -
Microsoft.VisualBasic.CompilerServices.IntegerType::FromString(string)
So the exception is coming from one of the following lines:
CInt("01")
CInt("02")
CInt("04")
CInt("08")
CInt("11")
CInt("20")
Any idea why do I get an exception?
Do I have to use [NumberFormatInfo and CultureInfo] whenever I parse
strings to numbers?
Thanks.
Atara.
'-- My Code:
Public Shared Function strDate2Date(ByVal strDate As String) As
System.DateTime
Dim isOk As Boolean = False
If (strDate Is Nothing) Then
isOk = False
ElseIf Not (strDate.Length() = 6) Then
isOk = False
Else
isOk = True
Dim yyyy As Integer = CInt(strDate.Substring(0, 2)) + 2000
Dim mm As Integer = CInt(strDate.Substring(2, 2))
Dim dd As Integer = CInt(strDate.Substring(4, 2))
Return (New System.DateTime(yyyy, mm, dd))
End If
Return Nothing
End Function
dim myDateCreated1 As System.DateTime = strDate2Date("020801") ' 1
Aug 2002
dim myDateCreated2 As System.DateTime = strDate2Date("040404") ' 4
Apr 2004
dim myDateCreated3 As System.DateTime = strDate2Date("040420") ' 20
Apr 2004
dim myDateCreated4 As System.DateTime = strDate2Date("041104") ' 4
Nov 2004
'-- Code till here.
On of my Italian client got the exception:
'-- Exception:
System.ArgumentException: The currency separator information specified
in the NumberFormatInfo is ambiguous for parsing.
at Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String
Value, NumberFormatInfo NumberFormat)
at
Microsoft.VisualBasic.CompilerServices.IntegerType.FromString(String
Value)
at myassembly.strDate2Date(String strDate)
'-- Exception till here.
When googling I understood that the VB compiler compiles CInt into -
Microsoft.VisualBasic.CompilerServices.IntegerType::FromString(string)
So the exception is coming from one of the following lines:
CInt("01")
CInt("02")
CInt("04")
CInt("08")
CInt("11")
CInt("20")
Any idea why do I get an exception?
Do I have to use [NumberFormatInfo and CultureInfo] whenever I parse
strings to numbers?
Thanks.
Atara.