[Implemented] Number base sensitive Val() functions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

[Implemented] Number base sensitive Val() functions

Post by Tipperton »

Since PureBasic has Bin() and Hex() funcitons,

A natural addition would be Val() functions that were number base sensitive using the first character of the string.

If the first character is a "%", treat it as binary
ElseIF the first character is a "$", treat it as hexadecimal
Else treat it as decimal

(I know you can write a function to do this but since the Bin and Hex commands exist, I just think it would be natural for Val to handle them as well)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

good point.

...at the moment, there is no reconversion of Bin() and Hex() ...?
oh... and have a nice day.
Chrono Syndrome
Enthusiast
Enthusiast
Posts: 169
Joined: Thu Oct 05, 2006 6:44 am
Contact:

Post by Chrono Syndrome »

Seconded.
Don't try to catch ze Night !
Remember: 'z' is better zen 'th' =) !
Sorry for bad english.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

In my optionion, this feature is not that good.

Imagine, you've got a string with trash or an input made by a user.
%127, $scalar, %11.10, 34h% etc. etc. etc.
The current behaviour of Val, converting a number as far as possible would lead to unexpected results:
Val("321meins") => 321
Val("%127") => 1 (there is no 2 and 7 in binary notation)

I think, it's a good idea, to make Val() and ValQ() accept Bin- and Hex-numbers, but it may lead to problems, using it with the exmaples above.

Maybe, you can also add a function like isNum() natively? If there is a function like isNum(), there should also be no problem with those "trash strings", because now you're able to check strings before the conversion.

These are just my thoughts and suggestions how to handle this request.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply