472,805 Members | 883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

CInt produce System.ArgumentException: "currency separator information is ambiguous for parsing"

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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
18 4757
Altara,

For your purpose is already a method, can you try this

Dim myDateCreated1 As System.DateTime = DateTime.ParseExact("020801",
"yyMMdd", Nothing) ' 1 Aug(2002)
Dim myDateCreated2 As System.DateTime = DateTime.ParseExact("040404",
"yyMMdd", Nothing) ' 4 Apr(2004)
Dim myDateCreated3 As System.DateTime = DateTime.ParseExact("040420",
"yyMMdd", Nothing) ' 20 Apr(2004)
Dim myDateCreated4 As System.DateTime = DateTime.ParseExact("041104",
"yyMMdd", Nothing) ' 4 Nov(2004)

I hope this helps?

Cor
Nov 21 '05 #2

Thanks, i will try it.
but I am also concerned for other code-lines in my program that I use -
Dim myInt As Integer = CInt(myStr)

Why do I get this exception for the first place?
atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Atara,

I do not see this, maybe you can try this on that one computer.

Dim myDateCreated1 As System.DateTime = New System.DateTime(2002, 8, 1) ' 1
Aug(2002)
Dim myDateCreated2 As System.DateTime = New System.DateTime(2004, 4, 4) ' 4
Apr(2004)
Dim myDateCreated3 As System.DateTime = New System.DateTime(2004, 4, 20) '
20 Apr(2004)
Dim myDateCreated4 As System.DateTime = New System.DateTime(2004, 11, 4) '
4 Nov(2004)

Because that is the only datetime affected part in your sample.

Accoording to this it should in my opinion works on every computer

http://msdn.microsoft.com/library/de...ctortopic2.asp

I hope this helps?

Cor
"Atara" <At***@DD.com> schreef in bericht
news:OY**************@TK2MSFTNGP09.phx.gbl...

Thanks, i will try it.
but I am also concerned for other code-lines in my program that I use -
Dim myInt As Integer = CInt(myStr)

Why do I get this exception for the first place?
atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4

Thanks for your efforts!

1. It is on a client computer, and I did not manage to reproduce the
same OS with the same languages on our computer. hopefully we will do it
within some hours.

2. The Exception occured at -
"Microsoft.VisualBasic.CompilerServices.IntegerTyp e.FromString(String
Value)"
and not on "System.DateTime.constructor"
Thanks. Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Atara,
As Cor suggests I would use DateTime.ParseExact in the strDate2Date routine.

As to the specifics of the exception:

Are certain that the input string contains only digits & not some other
character?

That you are not inadvertently doing:
dim myDateCreated1 As System.DateTime = strDate2Date("..,,..")

Or other invalid character sequences...

You could always include the debug program database (the .pdb file) for this
user.

If you are compiling with release build you can use "Project - Properties -
Configuration Properties - Build - Generate debugging information" then
install the .pdb file in the same folder as the executable. When you include
the .pdb file, the Stack Trace on Exceptions will include file names & line
numbers, allowing you to identify specifically which line had the problem.

Alternatively you could include a Try/Catch within strDate2Date to give
context information.

Something like:
Public Shared Function strDate2Date(ByVal strDate As String) As
System.DateTime
Try
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
Catch ex As Exception
Throw New ArgumentException("Invalid date parameter '" & strDate
& "'", "strDate", ex)
End Try
End Function

This way you will see what the parameter value was, I would consider
creating a new exception class that derives from ArgumentException that
included both the parameter name & its value (ala
ArgumentOutOfRangeException) instead of using ArgumentException directly.

Hope this helps
Jay

"Atara" <At***@DD.com> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6

Thanks you all for your efforts!
Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #7

Thanks you all for your efforts!
Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #8
Altara

Do you know what the problem was on that one computer with strange effects?

I am currious about that and it is as well good for this message thread when
it is searched on Google.

Cor
Nov 21 '05 #9
Altara

Do you know what the problem was on that one computer with strange effects?

I am currious about that and it is as well good for this message thread when
it is searched on Google.

Cor
Nov 21 '05 #10

I do not know yet. When I will have more info I will update this thread.

Thanks Cor.

Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #11

I do not know yet. When I will have more info I will update this thread.

Thanks Cor.

Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #12

I have asked my client about his "Regional Options", he did not answer
what they were, he only said that "the problem sprang from the
"International options" but now all is OK"

Thank you all for your time.

Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #13
info from another Italian client with the same error:
...
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 myXxx.cmcUtilities.strDate2Date(String strDate)
...

The client info:
I changed the decimal sign from dot to comma and now everithing works.

(I guess this is in -
'Control Panel' | 'Regional Options' | 'Currency'
(Atara))

The PC language is Italian as well as the operating system Windows XP.

I hope this will help others.

Atara.
*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #14
related thread:
'Local Settings and NumberFormat issues'

<URL:http://www.developersdex.com/vb/message.asp?r=4173188&p=1121>

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #15
Atara <At***@DD.com> wrote in news:uR**************@TK2MSFTNGP10.phx.gbl:
'Local Settings and NumberFormat issues'

<URL:http://www.developersdex.com/vb/message.asp?r=4173188&p=1121>


Thats the same thread thats currently under way here now. :)
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 21 '05 #16
related article:
<url: http://www.codeproject.com/vb/net/IsNumeric.asp>
Is it really Numeric
By Alberto Venditti
(Italy...)

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #17


and another thread: (Dutch)
<url:http://www.experts-exchange.com/Prog...ng_Languages/D
ot_Net/Q_20837350.html >

problem happened to our clients in Italy, Spain and Portugal.

Atara

*** Sent via Developersdex http://www.developersdex.com ***
Oct 31 '06 #18


To summarize:

Bug:
With some "Regional Options", any call to CInt() produces 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)

In my case it was when 'ControlPanel|Regional Options' , 'Decimal
Symbol' is a comma sign (,) .
It should be a dot sign (.) to avoid the bug.

Cause:
If any of the NumberFormatInfo group separators ( NumberGroupSeparator
| CurrencyGroupSeparator | PercentGroupSeparator)
is the same as any of the decimal separators (
NumberDecimalSeparator | CurrencyDecimalSeparator |
PercentDecimalSeparator),
Then parsing ambiguous strings produces unpredictable results.
Even when I parse simple strings with no seperators at all e.g.:
Dim myInt As integer = CInt("123")

Fix:
I started by replacing all -
' myInt = CInt(myNoInt)
with -
myInt = Integer.Parse(myNoInt)

but since I cannot replace AND test all ~100 appearances of CInt() in
my project
I added in my Main() :
Dim myCI As New System.Globalization.CultureInfo("en-US", False)
myCI.NumberFormat.NumberGroupSeparator = ","
myCI.NumberFormat.NumberDecimalSeparator = "."
' Note: This values are already set by default, but I re-set them
' for future versions that might not act the same.
System.Threading.Thread.CurrentThread.CurrentCultu re = myCI

It seems that the problem was fixed.

Atara.
*** Sent via Developersdex http://www.developersdex.com ***
Dec 4 '06 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill Stanard | last post by:
I have had no success using the format function as follows (the two lines of code run one after the other): 'displays a running total of lblAmtdue.Caption 'contents in txtTotal.Text...
5
by: Lasse Edsvik | last post by:
can you guys please tell me why i cant use currency as a name in my querystring? note: i NEED to use it since i'll be linking to a remote site were they get that info from querystring <%...
2
by: DC Gringo | last post by:
I have an image control (that pulls an image off an ESRI map server): <ASP:IMAGE ID="imgZonedCountry" RUNAT="server"></ASP:IMAGE> In the code behind I am setting the ImageURL to a String value...
7
by: Denis Samoilov | last post by:
We have a namespace N which includes enumeration ENUM1 and a class C with property C.Enum1, e.g. namespace N { public enum ENUM1{}; public class C { public ENUM1 Enum1 { get{} set{}
4
by: Gary Brown | last post by:
Hi, Why are fn(object parameters) and fn(params object parameters)
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.