?

Log in

No account? Create an account
Now here's a question for you: When is 50 greater than 300? Hint:… - 'Twas brillig, and the slithy toves did gyre and gimble in the wabe — LiveJournal [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

[Monday 20th June 2005 at 8:16 pm]
Thomas

boggyb
Now here's a question for you:

When is 50 greater than 300?

Hint: This is VB, and I have a textbox containing 50 and a textbox containing 300, and am comparing them with Text1 > Text2.
Link | Previous Entry | Share | Next Entry[ 9 pennies | Penny for your thoughts? ]

Comments:
[User Picture]From: pleaseremove
Monday 20th June 2005 at 7:26 pm (UTC)
Where the units for the 50 is elephants and the units for the 300 is chiwawas. and the comparison unit is weight.

Why do you persist in asking such simple questions?
(Reply) (Thread)
[User Picture]From: olego
Monday 20th June 2005 at 7:35 pm (UTC)
Without the hint it would've been too ambiguous; but with the hint it's too obvious. I think JavaScript is even more stupid about it than VB.
(Reply) (Thread)
[User Picture]From: boggyb
Monday 20th June 2005 at 7:39 pm (UTC)
Not tried that one in JavaScript.

By the way, this happens for the opposite reason that "1" + "1" = "2". (when I first used Strings in C++ (MFC CString class), I tried to stick them together with '&').
(Reply) (Parent) (Thread)
[User Picture]From: ralesk
Monday 20th June 2005 at 8:16 pm (UTC)
perl forever. > and gt rox0r y0r box0r.
(Reply) (Thread)
[User Picture]From: drkl1ght
Tuesday 21st June 2005 at 12:26 am (UTC)

2+2=5 (for extremely high values of 2)

I think that it's comparing them not as numbers, but as strings. "5" comes after "3", so it doesn't even check the next character.
(Reply) (Thread)
[User Picture]From: drkl1ght
Tuesday 21st June 2005 at 12:27 am (UTC)

Re: 2+2=5 (for extremely high values of 2)

But I figure you've already realized that.
(Reply) (Parent) (Thread)
[User Picture]From: boggyb
Tuesday 21st June 2005 at 10:50 am (UTC)

Re: 2+2=5 (for extremely high values of 2)

Yep, that's what's going on. My solution was to change it to Text1 > CDbl(Text2) which forces the second one to be treated as a number, and so forces them to be compared as numbers.
(Reply) (Parent) (Thread)
[User Picture]From: katayamma
Friday 1st July 2005 at 9:51 pm (UTC)
Integer vs Strings.

Yes, young padiwan, this is a common error made by many a programmer.

I come from the old school where you declared EVERY varaible type and convert numeric strings before doing ANYTHING to them.

Sloppy programming like what you encountered is why M$ is constantly having to publush patches. They tend to assume that the compiler will make everything good and right, when the truth is that it won't. The compiler cares nothing about what you want, only about how the code's written, and even then, what you THINK you wrote may not be what you really wrote. :P

Cheers
(Reply) (Thread)
[User Picture]From: boggyb
Saturday 2nd July 2005 at 4:06 pm (UTC)
The error that I don't make is the "1" + "1" = "2" one. I've learnt how to stick strings together properly. (when I first used C++ with MFC, I tried to stick CString's together with '&'. No prizes for guessing what happened).
(Reply) (Parent) (Thread)