For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > April 2005 > VBA IsNumeric equivalent









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author VBA IsNumeric equivalent
Joel

2005-04-06, 12:46 pm

In VBA, you can use IsNumeric to return True or False if the value being
tested is numeric. Is there an equivalent to this in VB.NET?
Ken Halter

2005-04-06, 12:46 pm

"Joel" <Joel@discussions.microsoft.com> wrote in message
news:414F9234-0E63-4B36-868D-19B215F288CF@microsoft.com...
> In VBA, you can use IsNumeric to return True or False if the value being
> tested is numeric. Is there an equivalent to this in VB.NET?


Not sure... if it's convenient then... probably not. Anyway, you'll want to
post that question in a .Net group. They all contain "dotnet" or "vsnet" in
their names.

This and all other groups on the MS server that start with
"microsoft.public.vb" are for VB Classic (VB versions 1-6) and were in
existance long before any .Net products were released. While some of the
code looks the same, they are very different products and require a
different set of groups.

Try one of these:
news://microsoft.public.dotnet.general
news://microsoft.public.dotnet.languages.vb


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..


Veign

2005-04-06, 12:46 pm

You mean something like;
System.Math.Comparison.Number.IsNumeric

is not convenient

(note: not the actual operator)

<vbg>

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/


"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:eImrjkTOFHA.3296@TK2MSFTNGP15.phx.gbl...
> "Joel" <Joel@discussions.microsoft.com> wrote in message
> news:414F9234-0E63-4B36-868D-19B215F288CF@microsoft.com...
>
> Not sure... if it's convenient then... probably not. Anyway, you'll want

to
> post that question in a .Net group. They all contain "dotnet" or "vsnet"

in
> their names.
>
> This and all other groups on the MS server that start with
> "microsoft.public.vb" are for VB Classic (VB versions 1-6) and were in
> existance long before any .Net products were released. While some of the
> code looks the same, they are very different products and require a
> different set of groups.
>
> Try one of these:
> news://microsoft.public.dotnet.general
> news://microsoft.public.dotnet.languages.vb
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Sign up now to help keep VB support alive - http://classicvb.org/petition
> Please keep all discussions in the groups..
>
>



Al Reid

2005-04-06, 12:46 pm

That is real close. I think it is something like:

Microsoft.VisualBasic.Information.IsNumeric

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain

"Veign" <NOSPAMinveign@veign.com> wrote in message news:%23V92t0TOFHA.244@TK2MSFTNGP12.phx.gbl...
> You mean something like;
> System.Math.Comparison.Number.IsNumeric
>
> is not convenient
>
> (note: not the actual operator)
>
> <vbg>
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> --
> Read. Decide. Sign the petition to Microsoft.
> http://classicvb.org/petition/
>
>
> "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
> news:eImrjkTOFHA.3296@TK2MSFTNGP15.phx.gbl...
> to
> in
>
>



Ken Halter

2005-04-06, 12:46 pm

"Veign" <NOSPAMinveign@veign.com> wrote in message
news:%23V92t0TOFHA.244@TK2MSFTNGP12.phx.gbl...
> You mean something like;
> System.Math.Comparison.Number.IsNumeric
>
> is not convenient


Yep... looks like, with .Net, the "fewer dots is always better" rule's been
thrown out the window eh? imo, it's ridiculous to have to memorize the
entire framework just to write code... might as well go back to assembler..
then, all you'd need to know is the processor's framework.... not a dot in
sight.

> (note: not the actual operator)
>
> <vbg>
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> --
> Read. Decide. Sign the petition to Microsoft.
> http://classicvb.org/petition/




--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Sign up now to help keep VB support alive - http://classicvb.org/petition
Please keep all discussions in the groups..


Veign

2005-04-06, 12:46 pm

Thats always been my issue...Trying to figure out the framework...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/


"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:OhjLyAUOFHA.2520@tk2msftngp13.phx.gbl...
> "Veign" <NOSPAMinveign@veign.com> wrote in message
> news:%23V92t0TOFHA.244@TK2MSFTNGP12.phx.gbl...
>
> Yep... looks like, with .Net, the "fewer dots is always better" rule's

been
> thrown out the window eh? imo, it's ridiculous to have to memorize the
> entire framework just to write code... might as well go back to

assembler..
> then, all you'd need to know is the processor's framework.... not a dot in
> sight.
>
>
>
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Sign up now to help keep VB support alive - http://classicvb.org/petition
> Please keep all discussions in the groups..
>
>



Veign

2005-04-06, 12:46 pm

Oh I forgot about the My namespace so it would be:
My.Number.WasThatANumberThatIPassed

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/


"Al Reid" <areidjr@reidDASHhome.com> wrote in message
news:ezPNg%23TOFHA.1732@TK2MSFTNGP14.phx.gbl...
> That is real close. I think it is something like:
>
> Microsoft.VisualBasic.Information.IsNumeric
>
> --
> Al Reid
>
> "It ain't what you don't know that gets you into trouble. It's what you

know
> for sure that just ain't so." --- Mark Twain
>
> "Veign" <NOSPAMinveign@veign.com> wrote in message

news:%23V92t0TOFHA.244@TK2MSFTNGP12.phx.gbl...
being[color=darkred]
want[color=darkred]
"vsnet"[color=darkred]
the[color=darkred]
http://classicvb.org/petition[color=darkred]
>
>



Paul Clement

2005-04-06, 12:46 pm

On Mon, 4 Apr 2005 14:32:56 -0400, "Veign" <NOSPAMinveign@veign.com> wrote:

¤ Oh I forgot about the My namespace so it would be:
¤ My.Number.WasThatANumberThatIPassed
¤

The qualification isn't required for items in the Microsoft.VisualBasic namespace.


Paul
~~~~
Microsoft MVP (Visual Basic)
Paul Clement

2005-04-06, 12:46 pm

On Mon, 4 Apr 2005 10:03:02 -0700, "Joel" <Joel@discussions.microsoft.com> wrote:

¤ In VBA, you can use IsNumeric to return True or False if the value being
¤ tested is numeric. Is there an equivalent to this in VB.NET?

Yes, it's called IsNumeric.

http://msdn.microsoft.com/library/d...ctisnumeric.asp


Paul
~~~~
Microsoft MVP (Visual Basic)
Rick Rothstein

2005-04-06, 12:46 pm

> ¤ In VBA, you can use IsNumeric to return True or False if the value
being
> ¤ tested is numeric. Is there an equivalent to this in VB.NET?
>
> Yes, it's called IsNumeric.
>
>

http://msdn.microsoft.com/library/d...ctisnumeric.asp

Note for Joel:

Depending on how you intend to use this function, caution may be
required. From a previous post of mine...

I usually try and steer people away from using IsNumeric to "proof"
supposedly numeric text. Consider this (also see note at end of post):

ReturnValue = IsNumeric("($1,23,,3.4,,,5,,E67$)")

Most people would not expect THAT to return True. IsNumeric has some
"flaws" in what it considers a proper number and what most programmers
are looking for.

I had a short tip published by Pinnacle Publishing in their Visual Basic
Developer magazine that covered some of these flaws. Originally, the tip
was free to view but is now viewable only by subscribers.. Basically, it
said that IsNumeric returned True for things like -- currency symbols
being located in front or in back of the number as shown in my example
(also applies to plus, minus and blanks too); numbers surrounded by
parentheses as shown in my example (some people use these to mark
negative numbers); numbers containing any number of commas before a
decimal point as shown in my example; numbers in scientific notation (a
number followed by an upper or lower case "D" or "E", followed by a
number equal to or less than 305 -- the maximum power of 10 in VB); and
Octal/Hexadecimal numbers (&H for Hexadecimal, &O or just & in front of
the number for Octal).

NOTE:
======
In the above example and in the referenced tip, I refer to $ signs and
commas and dots -- these were meant to refer to your currency, thousands
separator and decimal point symbols as defined in your local settings --
substitute your local regional symbols for these if appropriate.

As for your question about checking numbers, here are two functions that
I have posted in the past for similar questions..... one is for digits
only and the other is for "regular" numbers:

Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Len(Value) > 0 And _
Not Value Like "*[!0-9]*"
End Function

Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) > 0 And Value <> "." And _
Value <> vbNullString
End Function

Here are revisions to the above functions that deal with the local
settings for decimal points (and thousand's separators) that are
different than used in the US (this code works in the US too, of
course).

Function IsNumber(ByVal Value As String) As Boolean
Dim DP As String
' Get local setting for decimal point
DP = Format$(0, ".")
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9" & DP & "]*" And _
Not Value Like "*" & DP & "*" & DP & "*" And _
Len(Value) > 0 And Value <> DP And _
Value <> vbNullString
End Function

I'm not as concerned by the rejection of entries that include one or
more thousand's separators, but we can handle this if we don't insist on
the thousand's separator being located in the correct positions (in
other words, we'll allow the user to include them for their own
purposes... we'll just tolerate their presence).

Function IsNumber(ByVal Value As String) As Boolean
Dim DP As String
Dim TS As String
' Get local setting for decimal point
DP = Format$(0, ".")
' Get local setting for thousand's separator
' and eliminate them. Remove the next two lines
' if you don't want your users being able to
' type in the thousands separator at all.
TS = Mid$(Format$(1000, "#,###"), 2, 1)
Value = Replace$(Value, TS, "")
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9" & DP & "]*" And _
Not Value Like "*" & DP & "*" & DP & "*" And _
Len(Value) > 0 And Value <> DP And _
Value <> vbNullString
End Function

Rick - MVP

Paul Clement

2005-04-06, 9:01 pm

On Tue, 5 Apr 2005 10:26:35 -0400, "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote:

¤ > ¤ In VBA, you can use IsNumeric to return True or False if the value
¤ being
¤ > ¤ tested is numeric. Is there an equivalent to this in VB.NET?
¤ >
¤ > Yes, it's called IsNumeric.
¤ >
¤ >
¤ http://msdn.microsoft.com/library/d...ctisnumeric.asp
¤
¤ Note for Joel:
¤
¤ Depending on how you intend to use this function, caution may be
¤ required. From a previous post of mine...
¤
¤ I usually try and steer people away from using IsNumeric to "proof"
¤ supposedly numeric text. Consider this (also see note at end of post):
¤
¤ ReturnValue = IsNumeric("($1,23,,3.4,,,5,,E67$)")
¤

Haven't tried all the variations but this was fixed in Visual Basic.NET.


Paul
~~~~
Microsoft MVP (Visual Basic)
Rick Rothstein

2005-04-06, 9:01 pm

> ¤ > ¤ In VBA, you can use IsNumeric to return True or False if the
value
> ¤ being
> ¤ > ¤ tested is numeric. Is there an equivalent to this in VB.NET?
> ¤ >
> ¤ > Yes, it's called IsNumeric.
> ¤ >
> ¤ >
> ¤

http://msdn.microsoft.com/library/d...ctisnumeric.asp
> ¤
> ¤ Note for Joel:
> ¤
> ¤ Depending on how you intend to use this function, caution may be
> ¤ required. From a previous post of mine...
> ¤
> ¤ I usually try and steer people away from using IsNumeric to "proof"
> ¤ supposedly numeric text. Consider this (also see note at end of

post):
> ¤
> ¤ ReturnValue = IsNumeric("($1,23,,3.4,,,5,,E67$)")
> ¤
>
> Haven't tried all the variations but this was fixed in Visual

Basic.NET.

Of course that has no bearing here for VB6<g>, but at least its nice to
know that after all this time Microsoft finally addressed the problem.

[sarcasm] Wonder if Microsoft will migrate the fix back to VB6
[/sarcasm]

Still, I would think some caution will still be required in VB.NET.
Unless they have provided optional arguments to restrict the format of
the argument, an entry like 12e3 would still pass the IsNumeric function
but would more than likely not be acceptable to a TextBox entry
expecting digits only.

Rick - MVP

Bob Butler

2005-04-06, 9:01 pm

"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:%237gEbJuOFHA.2520@tk2msftngp13.phx.gbl
<cut>
>
> Of course that has no bearing here for VB6<g>, but at least its nice
> to know that after all this time Microsoft finally addressed the
> problem.


OTOH it's another example of a change in what has been long-term,
well-defined behavior of VB and something that may cause apps to behave
differently. It was crap like that that made it glaringly obvious to me
that MS had dropped all pretense at providing the kind of support that
developers need if they are going to rely on a toolset.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Paul Clement

2005-04-07, 4:03 pm

On Wed, 6 Apr 2005 15:28:30 -0700, "Bob Butler" <tiredofit@nospam.com> wrote:

¤ "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
¤ news:%237gEbJuOFHA.2520@tk2msftngp13.phx.gbl
¤ <cut>
¤ >> Haven't tried all the variations but this was fixed in Visual
¤ >> Basic.NET.
¤ >
¤ > Of course that has no bearing here for VB6<g>, but at least its nice
¤ > to know that after all this time Microsoft finally addressed the
¤ > problem.
¤
¤ OTOH it's another example of a change in what has been long-term,
¤ well-defined behavior of VB and something that may cause apps to behave
¤ differently.

Yes, it was a shame they modified the behavior. I'm sure most VB developers would be disappointed to
find out that the function didn't continue to fail as expected (or unexpectedly for those who aren't
aware of the bug). ;-)


Paul
~~~~
Microsoft MVP (Visual Basic)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com