Re: Local Settings and NumberFormat issues
ru <ur@sx3all.be > wrote in
news:10l8b1lc2u j5b0t6qvv9i2ddo v1rhuau81@4ax.c om:[color=blue]
> I'm not aware of bypassing the system routines for parsing - how does
> one do that :) Can you give me an example?[/color]
Developers often write their own parsing routines, especially on non .NET platforms where the
frameworks may not support it, or worse yet the frameworks rely on configurations from the
developer and ignore the system settings.
[color=blue]
> int100 = CInt(txt100.Tex t)
>
> int100 is an integer
> txt100 is a textbox displaying an integer variable: there's no decimal
> separator involved, so I don't know why this is raising an error.[/color]
Im more of a C# person than a VB person although before Delphi I used to do a lot of VB and
even wrote for many magizines. CInt I know is a type of VB.NET cast but under the hood I dont
remember what its C# equivalent is, IIRC its more equivalent to an implicit cast in VB.NET than a
parse. Generally I would recommend against these and prefer the parse methods.
Does it have a thousands separator in it possibly?
[color=blue]
> Changing the code to:
> int100 = Integer.Parse(t xt100History.Te xt,
> NumberStyles.Al lowDecimalPoint )
> cleared the error.[/color]
Does just Parse(txt100His tory.Text) work for you or must you specify the second argument? What
is the exact string value of txt100Histor.Te xt when the exception is thrown?
[color=blue]
> Another thing I discovered was that the IsNumeric function also didn't
> work properly. The following code would always return false, no matter
> what key was pressed:
>
> Private Sub txtScore_TextCh anged(ByVal sender As Object, ByVal e As
> System.EventArg s) Handles txtScore.TextCh anged
> If IsNumeric(txtSc ore.Text) = False Then
> txtScore.Text = ""
> End If
> 'End Sub[/color]
Isnt IsNumeric one of the old VB comptability routines? Generally speaking you should avoid
using these in new code and rely on FCL functionality instead. And is it possible that IsNumeric
only checks the first character in the string? I seem to remember something about this from the
long ago VB days.
[color=blue]
> I now notice that only parsing of variables from the form itself,
> displayed by labels or textboxes, is causing troubles. I just tested a
> conversion from an integer declared in code to a double to a string
> without errors.[/color]
Quite possibly because when you are dispalying it, regional settings are formatting it. Then when
you are rereading it, its formatted.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
Empower ASP.NET with IntraWeb
ru <ur@sx3all.be > wrote in
news:10l8b1lc2u j5b0t6qvv9i2ddo v1rhuau81@4ax.c om:[color=blue]
> I'm not aware of bypassing the system routines for parsing - how does
> one do that :) Can you give me an example?[/color]
Developers often write their own parsing routines, especially on non .NET platforms where the
frameworks may not support it, or worse yet the frameworks rely on configurations from the
developer and ignore the system settings.
[color=blue]
> int100 = CInt(txt100.Tex t)
>
> int100 is an integer
> txt100 is a textbox displaying an integer variable: there's no decimal
> separator involved, so I don't know why this is raising an error.[/color]
Im more of a C# person than a VB person although before Delphi I used to do a lot of VB and
even wrote for many magizines. CInt I know is a type of VB.NET cast but under the hood I dont
remember what its C# equivalent is, IIRC its more equivalent to an implicit cast in VB.NET than a
parse. Generally I would recommend against these and prefer the parse methods.
Does it have a thousands separator in it possibly?
[color=blue]
> Changing the code to:
> int100 = Integer.Parse(t xt100History.Te xt,
> NumberStyles.Al lowDecimalPoint )
> cleared the error.[/color]
Does just Parse(txt100His tory.Text) work for you or must you specify the second argument? What
is the exact string value of txt100Histor.Te xt when the exception is thrown?
[color=blue]
> Another thing I discovered was that the IsNumeric function also didn't
> work properly. The following code would always return false, no matter
> what key was pressed:
>
> Private Sub txtScore_TextCh anged(ByVal sender As Object, ByVal e As
> System.EventArg s) Handles txtScore.TextCh anged
> If IsNumeric(txtSc ore.Text) = False Then
> txtScore.Text = ""
> End If
> 'End Sub[/color]
Isnt IsNumeric one of the old VB comptability routines? Generally speaking you should avoid
using these in new code and rely on FCL functionality instead. And is it possible that IsNumeric
only checks the first character in the string? I seem to remember something about this from the
long ago VB days.
[color=blue]
> I now notice that only parsing of variables from the form itself,
> displayed by labels or textboxes, is causing troubles. I just tested a
> conversion from an integer declared in code to a double to a string
> without errors.[/color]
Quite possibly because when you are dispalying it, regional settings are formatting it. Then when
you are rereading it, its formatted.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
Empower ASP.NET with IntraWeb
Comment