converting a string 2 an integer

New to FreeBASIC? Post your questions here.
Post Reply
ShadowDust
Posts: 274
Joined: Oct 13, 2005 2:05
Contact:

converting a string 2 an integer

Post by ShadowDust »

can some one show me how to convert a string in to an integer? please?
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Post by MystikShadows »

Hi ShadowDust

Try

Code: Select all

DIM IntegerValue AS INTEGER

IntegerValue = VAL("3423")

PRINT IntegerValue

Rattrapmax6
Posts: 334
Joined: May 29, 2005 1:45
Location: At my Computer
Contact:

Post by Rattrapmax6 »

Example with a string variable:

Code: Select all

Strng$ = "100"

Num = VAL(Strng$)

PRINT Num
;)
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Hello!

Can anyone tell me which non-string variable can contain a hex value?

If this cant be done, how do I use a string containing a hex value as an integer?

Example:

Circle (x, y), z, &h(variable containing color hex value)


thanks,
h4tt3n
jofers
Posts: 1525
Joined: May 27, 2005 17:18

Post by jofers »

"&h" is only for literal expressions, like &h40, or &h24. Internally, the computer only knows numbers (well, technically, binary). So if you do this:

Code: Select all

x = &h40
It's the exact same as doing this:
x = 64
There's literally no difference. So you can do this:

Code: Select all

c = &h30
Circle (x, y), z, c
HOWEVER, colors are a little simpler if you forgo the HTML convention and use the RGB macro:

Code: Select all

Circle(x, y), z, Rgb(255, 128, 0)
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Cool, thanks! :-D

This problem really bugged me.

regards,
h4tt3n
Post Reply