473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why IsNumeric("5-") is true?

Can anybody tell why IsNumeric("5-") is true?
May 9 '07 #1
9 2302
Tony,

Why not, that is common here, be aware that this method is to check strings
from textboxes

Cor

"Tony" <To**@discussio ns.microsoft.co mschreef in bericht
news:5D******** *************** ***********@mic rosoft.com...
Can anybody tell why IsNumeric("5-") is true?

May 10 '07 #2
This is a legacy VB/VBA function that returns true if the value *starts*
with something usable (working in conjonction with Val that will properly
convert something that starts with a number).

If you want to be strict on possible values, it is best to use other
functions such as TryParse...

---
Patrice

"Tony" <To**@discussio ns.microsoft.co ma écrit dans le message de news:
5D************* *************** **...icrosof t.com...
Can anybody tell why IsNumeric("5-") is true?

May 10 '07 #3
Maybe you could tell us why you thingk it shouldn't be.
"Tony" <To**@discussio ns.microsoft.co mwrote in message
news:5D******** *************** ***********@mic rosoft.com...
Can anybody tell why IsNumeric("5-") is true?
May 10 '07 #4
Patrice,

That is not how IsNumeric works.

If it did work that way then, for example, IsNumeric("5B") would return
True, but it returns False.

Kerry Moorman
"Patrice" wrote:
This is a legacy VB/VBA function that returns true if the value *starts*
with something usable (working in conjonction with Val that will properly
convert something that starts with a number).

If you want to be strict on possible values, it is best to use other
functions such as TryParse...

---
Patrice

"Tony" <To**@discussio ns.microsoft.co ma écrit dans le message de news:
5D************* *************** **...icrosof t.com...
Can anybody tell why IsNumeric("5-") is true?


May 10 '07 #5
Tony wrote:
Can anybody tell why IsNumeric("5-") is true?
It represents a number just less than 5, like 5+ represents a number just
greater than 5.

For example, you might encounter something like "the limit of 1/x as x->0-
...." (where -is meant to represent an arrow) which means the limit of 1/x
as x approaches zero from the negative side.

See it written as a superscript at http://mathworld.wolfram.com/Limit.html
(amusing cartoon at end of page, too :-)

Andrew
May 10 '07 #6
Good point. I probably forgot how it works exactly. The bottom line is that
this function can return true in some cases even if the "number" is not
strictly a number so your best bet is to use another function that does a
more strict checking...

P.S. I finally gave it a try using the following code :

Dim a() As String = {"&h5", "5?", "5 6"} ' Use your own currency
symbol instead of ?
Dim r As Integer
For i As Integer = 0 To UBound(a)
Debug.WriteLine (String.Format( "{0},{1},{2 }", a(i),
IsNumeric(a(i)) , Integer.TryPars e(a(i), r)))
Next

Results are :

&h5,True,Fal se
5?,True,False
5 6,True,False

As you can see IsNumeric is not as picky than TryParse (and was already in
VB/VBA so they likely kept this unchanged for compatibility). ..
--
Patrice

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.coma écrit dans le
message de news: 5D************* *************** **...icrosof t.com...
Patrice,

That is not how IsNumeric works.

If it did work that way then, for example, IsNumeric("5B") would return
True, but it returns False.

Kerry Moorman
"Patrice" wrote:
>This is a legacy VB/VBA function that returns true if the value *starts*
with something usable (working in conjonction with Val that will properly
convert something that starts with a number).

If you want to be strict on possible values, it is best to use other
functions such as TryParse...

---
Patrice

"Tony" <To**@discussio ns.microsoft.co ma écrit dans le message de news:
5D************* *************** **...icrosof t.com...
Can anybody tell why IsNumeric("5-") is true?



May 10 '07 #7
Thanks, Andrew.
I guess you are right. Even I can not find it from VB reference.

Tony

"Andrew Morton" wrote:
Tony wrote:
Can anybody tell why IsNumeric("5-") is true?

It represents a number just less than 5, like 5+ represents a number just
greater than 5.

For example, you might encounter something like "the limit of 1/x as x->0-
...." (where -is meant to represent an arrow) which means the limit of 1/x
as x approaches zero from the negative side.

See it written as a superscript at http://mathworld.wolfram.com/Limit.html
(amusing cartoon at end of page, too :-)

Andrew
May 11 '07 #8
In fact, if I try to CInt("5-"), I will get -5. So I guess VB treat it as -5. ?

"Tony" wrote:
Thanks, Andrew.
I guess you are right. Even I can not find it from VB reference.

Tony

"Andrew Morton" wrote:
Tony wrote:
Can anybody tell why IsNumeric("5-") is true?
It represents a number just less than 5, like 5+ represents a number just
greater than 5.

For example, you might encounter something like "the limit of 1/x as x->0-
...." (where -is meant to represent an arrow) which means the limit of 1/x
as x approaches zero from the negative side.

See it written as a superscript at http://mathworld.wolfram.com/Limit.html
(amusing cartoon at end of page, too :-)

Andrew

May 11 '07 #9
We are really interested to know what you why it shouldn't be interpreted
as -5.
"Tony" <To**@discussio ns.microsoft.co mwrote in message
news:DB******** *************** ***********@mic rosoft.com...
In fact, if I try to CInt("5-"), I will get -5. So I guess VB treat it
as -5. ?

"Tony" wrote:
>Thanks, Andrew.
I guess you are right. Even I can not find it from VB reference.

Tony

"Andrew Morton" wrote:
Tony wrote:
Can anybody tell why IsNumeric("5-") is true?

It represents a number just less than 5, like 5+ represents a number
just
greater than 5.

For example, you might encounter something like "the limit of 1/x as
x->0-
...." (where -is meant to represent an arrow) which means the limit
of 1/x
as x approaches zero from the negative side.

See it written as a superscript at
http://mathworld.wolfram.com/Limit.html
(amusing cartoon at end of page, too :-)

Andrew
May 11 '07 #10

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

Similar topics

46
4201
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
3
2560
by: drs | last post by:
I just upgraded my Python install, and for the first time have True and False rather than 1 and 0. I was playing around at the command line to test how they work (for instance, "if 9:" and "if True:" both lead to the conditional being executed, but True == 9 -> False, that this would be true was not obvious to me -- "True is True" is True,...
35
3366
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
36
42395
by: Remi Villatel | last post by:
Hi there, There is always a "nice" way to do things in Python but this time I can't find one. What I'm trying to achieve is a conditionnal loop of which the condition test would be done at the end so the loop is executed at least once. It's some way the opposite of "while". So far, all I got is:
14
2458
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a "counted" string and data in a binary file. Given... #include <stdio.h> int main(int argc, char *argv) { char bstring;
48
30092
by: Skybuck Flying | last post by:
Hi, I came across this C code which I wanted to understand etc it looked like this: if (-1) etc It made me wonder what the result would be... true or false ? In C and Delphi
33
2488
by: Ruffin Bailey | last post by:
I coulda sworn I was given an explanation during an AppDev class years ago for VB6, but don't recall the answer. Why is it that -1 is True in Visual Basic (and now VB.NET)? Bit flags seem like they should always be 0 or 1 to me... (not that I haven't used VB long enough by now to know better). Sorry to pester, but "why is -1 = true?" is a...
90
3394
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
2
7388
by: Ultrak The DBA | last post by:
Using the following query: select substr(reg_var_name,1,24) as reg_var_name, substr(reg_var_value, 1,12) as reg_var_value, level from table(sysproc.reg_list_variables()) as registryinfo; I am receiving this information from hitting several of our prod databases: ADB1291.autostart:DB2AUTOSTART TRUE I...
40
2706
by: nufuhsus | last post by:
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5718
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...
0
5394
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...
0
3844
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...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
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
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.