Textbox.text, Input to Integer

  • Thread starter Thread starter Guest
  • Start date Start date
* "Cor Ligthert said:
I think in this case it is than allowed to enclose this messages including
the isnumeric in a try and catch block, because of the fact that the
keyboard device can give unpredictable results. I did not know that it was
accepting this kind of numerics

So, I would not use 'IsNumeric' in this situation ;-).
 
So, I would not use 'IsNumeric' in this situation ;-).What than, in the other thread the OP shows he wants that keyboard keypress
event with that

TextBox1.SelectionStart = TextBox1.Text.Length and that with a -1 when the
backspace is pushed, however I think in another situation this is very good.

Try
if isnumeric
bla

Catch
is a very big exception so no problem

End Try

However show me your (simple) alternative

Cor
 
* "Cor Ligthert said:
What than, in the other thread the OP shows he wants that keyboard keypress
event with that

TextBox1.SelectionStart = TextBox1.Text.Length and that with a -1 when the
backspace is pushed, however I think in another situation this is very good.

Try
if isnumeric
bla

So, why do you need 'IsNumeric' at all?
Catch
is a very big exception so no problem

End Try

However show me your (simple) alternative

IMO, that's a very user-friendly way:

\\\
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim EventSource As TextBox = DirectCast(sender, TextBox)
Try
Dim i As Integer = Integer.Parse(EventSource.Text)
If Me.ErrorProvider1.GetError(EventSource).Length > 0 Then
Me.ErrorProvider1.SetError(EventSource, "")
End If
Catch ex As Exception
Me.ErrorProvider1.SetError(EventSource, "Value must be an integer. (" & ex.Message & ")")
End Try
End Sub
///
 
Hi Herfried,

Look what you wrote yourself (and me as well) to Kudzu,

By using the IsNumeric all errors will be trapped by the Isnumeric, which
cost no time, however when there is an exceptional error (an overflow) it
will be catched by the Catch.

I think that is the right approach,

Cor
 
(e-mail address removed) (Herfried K. Wagner [MVP]) wrote in
Definitely no. On my PII 350 it sometimes takes 2 to 5 seconds.

Just to eb sure - we are talking abotu this:

try
throw some excetpion
catch
code here
end try

THIS takes 2-5 seconds on your machine? Does it only take that long in th
debugger for you? If so your VS is hosed - you really need a reinstall.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
 
* "Cor Ligthert said:
Look what you wrote yourself (and me as well) to Kudzu,

I know. It was only a note, not a recommendation not to use
'Try...Catch' at all.
By using the IsNumeric all errors will be trapped by the Isnumeric, which
cost no time, however when there is an exceptional error (an overflow) it
will be catched by the Catch.

I doubt that the performance of 'IsNumeric' is very good. 'IsNumeric'
is very general, it will work with hexadecimal and octal numbers and
numbers in various other styles.
I think that is the right approach,

'Integer.TryParse' is the right approach, but that's .NET 2.0.
 
I doubt that the performance of 'IsNumeric' is very good. 'IsNumeric'
is very general, it will work with hexadecimal and octal numbers and
numbers in various other styles.

IsNumeric does not take 2 to 3 seconds probably something as 2 to 3 pico
seconds and in that we go to the part where Kudzu and I do very much agree.

Cor
 
* "Chad Z. Hower aka Kudzu said:
Just to eb sure - we are talking abotu this:

try
throw some excetpion
catch
code here
end try

THIS takes 2-5 seconds on your machine? Does it only take that long in th
debugger for you? If so your VS is hosed - you really need a reinstall.

No, it's my old machine. And yes, it's the debug version.
 

Do you guys have any virus scanners or other running? Can you send me a
simple app to demonstrate this? One that even logs its own time and displays
it I think is best so we can accurately compare times.
Kuzdu is right, the problem is not as big in a release version.

In release it should be negligible - in the milliseconds at most.


--
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/
 
PS - not that I want to drag Delphi in - but Delphi for the .NET framework I
can tell you for sure does not stop for several seconds on try..catch, and
I've never had my VS do it either. Thats why Id like to try a project thats
slow on your machine.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
* "Chad Z. Hower aka Kudzu said:
PS - not that I want to drag Delphi in - but Delphi for the .NET framework I
can tell you for sure does not stop for several seconds on try..catch, and
I've never had my VS do it either. Thats why Id like to try a project thats
slow on your machine.

Mhm... I don't have such a project on my machine at the moment because
the "old" machine doesn't currently have VS.NET installed :-(.
 
(e-mail address removed) (Herfried K. Wagner [MVP]) wrote in
Mhm... I don't have such a project on my machine at the moment because
the "old" machine doesn't currently have VS.NET installed :-(.

And it only takes abnormally long on your old machine?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
Chad,

* "Chad Z. Hower aka Kudzu said:
And it only takes abnormally long on your old machine?

Yes. I mixed up my debugging experience on the old machine with the
release behavior (I hardly ever run my applications in release mode).

I remember that catching exceptions took very long when accessing a
prostgresql database running in cygwin, but I assume that this had other
reasons.
 
Back
Top