Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with arrays
#1
we were recieving this error "type not defined"

Code:
SUB SHIPCHOOSE
A = 1
TYPE SHIPSTATS
  NAYM AS STRING * 10
END TYPE
DIM SHIP(A) AS SHIPSTATS
SHIP(1).NAYM = "COW"
CLS
PRINT SHIP(1).NAYM
END SUB
-yah
Reply
#2
"we" being your programming class?
Reply
#3
First of all, it's summer vacation right now. So programming is not untill school. And the class is second semester anyways.

Secondly, WE refers to me and my pal Jeremeie, for we are on a full night programming marathon.
-yah
Reply
#4
Advice 1: There are better things to do at night rather than a programming marathon.

Now on topic: AFAIK, you can't define a type structure inside a SUB. You have to do it at the beginning of your code, as it is declarative stuff which should be processed at first.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
Oh ok, it works now. Thanks.
-yah
Reply
#6
Quote:Advice 1: There are better things to do at night rather than a programming marathon.

NO WAI!!!!11
Reply
#7
Quote:you can't define a type structure inside a SUB

Don't you hate error messages like that? You would think the program would halt at the TYPE statement with the message "TYPE is illegal except in MAIN" or something like that.

QBasic is full of error messages that confuse people. For example, if you mess up a DATA statement, it is the READ statement that is flagged. And it doesn't say "Unable to read bogus DATA". Noooo. It gives "Syntax Error" as if there is something wrong with your READ statement syntax.

Mumble, grumble.....

Mac
Reply
#8
Compiling with bc will give both errors in the expected order:
Code:
0040   0006      TYPE fooType
                  ^ TYPE statement improperly nested
                  ^ Skipping forward to END TYPE statement
0040   0006      DIM f AS fooType
                           ^ TYPE not defined
The Qbasic interpreter gives only one error message before stopping. Possibly whats happening is that the declarations are checked first, if you remove the dim statement then Qbasic will give an error message about the type being defined inside a sub.

Quote:QBasic is full of error messages that confuse people.
All compilers/interpreters have error messages that confuse people. Its very hard to write compilers that give good error messages since they don't know that the programmer was actually trying to do.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#9
That code compiles and runs as expected, in the latest CVS version of FB, using the "-lang qb" compiler option

Funny, eh?
Reply
#10
Quote:QBasic is full of error messages that confuse people.

Thats the fun part! :b
-yah
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)