473,714 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

In my apllication I use the following code:

'-- My Code:
Public Shared Function strDate2Date(By Val 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.Su bstring(0, 2)) + 2000
Dim mm As Integer = CInt(strDate.Su bstring(2, 2))
Dim dd As Integer = CInt(strDate.Su bstring(4, 2))
Return (New System.DateTime (yyyy, mm, dd))
End If
Return Nothing
End Function

dim myDateCreated1 As System.DateTime = strDate2Date("0 20801") ' 1
Aug 2002
dim myDateCreated2 As System.DateTime = strDate2Date("0 40404") ' 4
Apr 2004
dim myDateCreated3 As System.DateTime = strDate2Date("0 40420") ' 20
Apr 2004
dim myDateCreated4 As System.DateTime = strDate2Date("0 41104") ' 4
Nov 2004
'-- Code till here.

On of my Italian client got the exception:

'-- Exception:
System.Argument Exception: The currency separator information specified
in the NumberFormatInf o is ambiguous for parsing.
at Microsoft.Visua lBasic.Compiler Services.Double Type.Parse(Stri ng
Value, NumberFormatInf o NumberFormat)
at
Microsoft.Visua lBasic.Compiler Services.Intege rType.FromStrin g(String
Value)
at myassembly.strD ate2Date(String strDate)
'-- Exception till here.

When googling I understood that the VB compiler compiles CInt into -
Microsoft.Visua lBasic.Compiler Services.Intege rType::FromStri ng(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 [NumberFormatInf o 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 4873
Altara,

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

Dim myDateCreated1 As System.DateTime = DateTime.ParseE xact("020801",
"yyMMdd", Nothing) ' 1 Aug(2002)
Dim myDateCreated2 As System.DateTime = DateTime.ParseE xact("040404",
"yyMMdd", Nothing) ' 4 Apr(2004)
Dim myDateCreated3 As System.DateTime = DateTime.ParseE xact("040420",
"yyMMdd", Nothing) ' 20 Apr(2004)
Dim myDateCreated4 As System.DateTime = DateTime.ParseE xact("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******** ******@TK2MSFTN GP09.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.Visu alBasic.Compile rServices.Integ erType.FromStri ng(String
Value)"
and not on "System.DateTim e.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.ParseE xact 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(By Val 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.Su bstring(0, 2)) + 2000
Dim mm As Integer = CInt(strDate.Su bstring(2, 2))
Dim dd As Integer = CInt(strDate.Su bstring(4, 2))
Return (New System.DateTime (yyyy, mm, dd))
End If
Return Nothing
Catch ex As Exception
Throw New ArgumentExcepti on("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 ArgumentExcepti on that
included both the parameter name & its value (ala
ArgumentOutOfRa ngeException) instead of using ArgumentExcepti on directly.

Hope this helps
Jay

"Atara" <At***@DD.com > wrote in message
news:O7******** ******@TK2MSFTN GP09.phx.gbl...
In my apllication I use the following code:

'-- My Code:
Public Shared Function strDate2Date(By Val 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.Su bstring(0, 2)) + 2000
Dim mm As Integer = CInt(strDate.Su bstring(2, 2))
Dim dd As Integer = CInt(strDate.Su bstring(4, 2))
Return (New System.DateTime (yyyy, mm, dd))
End If
Return Nothing
End Function

dim myDateCreated1 As System.DateTime = strDate2Date("0 20801") ' 1
Aug 2002
dim myDateCreated2 As System.DateTime = strDate2Date("0 40404") ' 4
Apr 2004
dim myDateCreated3 As System.DateTime = strDate2Date("0 40420") ' 20
Apr 2004
dim myDateCreated4 As System.DateTime = strDate2Date("0 41104") ' 4
Nov 2004
'-- Code till here.

On of my Italian client got the exception:

'-- Exception:
System.Argument Exception: The currency separator information specified
in the NumberFormatInf o is ambiguous for parsing.
at Microsoft.Visua lBasic.Compiler Services.Double Type.Parse(Stri ng
Value, NumberFormatInf o NumberFormat)
at
Microsoft.Visua lBasic.Compiler Services.Intege rType.FromStrin g(String
Value)
at myassembly.strD ate2Date(String strDate)
'-- Exception till here.

When googling I understood that the VB compiler compiles CInt into -
Microsoft.Visua lBasic.Compiler Services.Intege rType::FromStri ng(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 [NumberFormatInf o 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

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

Similar topics

1
8857
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 txtTotal.Text = lblAmtdue.Caption + Val(txtTotal.Text) 'tries to format contents of txtTotal.Text as currency; doesn't work txtTotal.Text = Format$(txtTotal.Text, "Currency")
5
1911
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 <% curr="SEK" %> <html>
2
1847
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 with url parameters like this: imgZonedCountry.ImageUrl = "http://server/servlet/com.esri.wms.Esrimap?param1=x&param2=y When it serves up the page, I'm getting "&amp;" in place of the "&"
7
6758
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
2036
by: Gary Brown | last post by:
Hi, Why are fn(object parameters) and fn(params object parameters)
0
9306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7942
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3155
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.