DIM Bug ??

General FreeBASIC programming questions.
Post Reply
redcrab
Posts: 623
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

DIM Bug ??

Post by redcrab »

If I have

Code: Select all

dim x,y as integer
x = 10
y = 11
it compiles
but

Code: Select all

dim x,y as String
x = "hello"
y="byebye"
it doesn't compile saying : error 26 invalid data type on ' x = "helo" '

Do i miss something ?
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:

Post by voodooattack »

you have to do:

dim x as string, y as string

in your code, the 1st variable is missing the 'as' part, so the compiler assumes its the default data type, which is integer in FB (or at least numerical, as i guess)

your code would work in VB, since it has a default data type (variant) that can encapsulate all other types..

:)
Stormy
Posts: 198
Joined: May 28, 2005 17:57
Location: Germany
Contact:

Post by Stormy »

An alternative is:

Code: Select all

DIM AS STRING x, y
and both vars will be strings...
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

Or you could something like this:

Code: Select all

dim as string x,y
x = "hello "
y = "world!"
print x;y
sleep
Declare the data type first then your variables. I tried it and it works.
redcrab
Posts: 623
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Post by redcrab »

Thanks
that was the coding tips i'm looking for .

I'm sometime bored to make multiple "dim as" for the same data type,
I'm quite lazy on the keyboard and clipboard :D
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

I use to dim each variable seperately and didn't know about : so I'd do this:

Code: Select all

dim x as string
dim y as string
dim n as integer
...
That was painful, then I learnt about : so I was going:

Code: Select all

dim x as string:dim y as string:dim n as integer:...
Then I figured out what I told you by pasting

Code: Select all

dim  as string
As a neutral line then I just fill in what I need to and put the variable after it but forgot to comment them and ran it and it worked.
lol, got to love it when something works out when you least expect it.
Post Reply