CLng, CInt, CByte, CWord ... conversions would be nice...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

CLng, CInt, CByte, CWord ... conversions would be nice...

Post by Shannara »

I currently have a string that consists of one number "1". I would like to convert it to a long, or even a byte. How can I do this? I couldnt find any conversions in the PB manual. Except for the String (STR), but that was it. This is needed to read numbers from a combo box by NOT using the index, but by reading the text of an element.

I think the above would be quite usefull.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

number.l = Val(string$) doesn't work?

or am I missing the point here?

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Didn't see that one coming.. hopefully it'll work with bytes. As I know PB has a problem assigning a long (that is less then 128) to a byte.
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

Hi Shannara:
Is this any help?

Code: Select all

s$="1"
A.L=PeekB(@s$)-48
Debug "Long :"+Str(A)
B.b=PeekB(@s$)-48 
Debug "Byte :" +Str(B)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Shannara wrote:Didn't see that one coming.. hopefully it'll work with bytes. As I know PB has a problem assigning a long (that is less then 128) to a byte.
if the long is in the byte range, it works perfectly... We did you find this assumption ?
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Einander:

Thanks, I'll do a test, if that works, I'll create small lib for the bugger.


Fred:

hrm, I think your probably right, I was passing a 100 byte value into a proc that accepted only longs, and then took that 100 long value and passed it to a byte variable... maybe somewhere in there...
Post Reply