DIM Bug ??

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

DIM Bug ??

Postby redcrab » Feb 18, 2006 13:40

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:

Postby voodooattack » Feb 18, 2006 13:51

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:

Postby Stormy » Feb 18, 2006 14:35

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
Contact:

Postby axipher » Feb 18, 2006 14:41

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: 619
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Postby redcrab » Feb 18, 2006 14:48

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
Contact:

Postby axipher » Feb 18, 2006 14:57

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.

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests