Anyone know Quickbasic?

I’m working on a program and I’m stumped. The whole thing was working fine until I got to the part where I had to put a complex bit of data into a file. I created a little test routine to try and do it and I keep getting a “Type Mismatch” error and I don’t see why. I defined it as a 3 length string and it IS one. Unless, of course, I’m doing something wrong. But I don’t see it and after 2+ hours of scanning books (three books for a combined 2500+ pages) and surfing the net, I am, as I said, stumped.

Can anyone tell me why I keep getting a type mismatch is the marked line (sorry for the length, but I’m including the wohole thing in case the mistake is from somewhere else in the program).


OPTION BASE 1
TYPE test
 **nm AS STRING * 3 REM <<<test.nm defined here**
 aexc AS LONG
 a2 AS LONG
 a3 AS LONG
 a4 AS LONG
 a5 AS LONG
 a6 AS LONG
 a7 AS LONG
 a8 AS LONG
 a9 AS LONG
 a10 AS LONG
 a11 AS LONG
 a12 AS LONG
 a13 AS LONG
 a14 AS LONG
 a15 AS LONG
 a16 AS LONG
 a17 AS LONG
 a18 AS LONG
 a19 AS LONG
 a20 AS LONG
 a21 AS LONG
 a22 AS LONG
 a23 AS LONG
 a24 AS LONG
 a25 AS LONG
 a26 AS LONG
 a27 AS LONG
 a28 AS LONG
 a29 AS LONG
 a30 AS LONG
 a31 AS LONG
 a32 AS LONG
 a33 AS LONG
 a34 AS LONG
 a35 AS LONG
 a36 AS LONG
 a37 AS LONG
 a38 AS LONG
END TYPE
INPUT ; "filename"; q$
q$ = q$ + ".dxt"
OPEN q$ FOR RANDOM AS #1 LEN = 155
DIM b(38) AS LONG
FOR x = 1 TO 38
 b(x) = 30
NEXT x
**z$ = "~~~" REM <<<test.nm initialized here
test.nm = z$ REM <<<Type Mismatch here **
test.exc = b(1)
test.a2 = b(2)
test.a3 = b(3)
test.a4 = b(4)
test.a5 = b(5)
test.a6 = b(6)
test.a7 = b(7)
test.a8 = b(8)
test.a9 = b(9)
test.a10 = b(10)
test.a11 = b(11)
test.a12 = b(12)
test.a13 = b(13)
test.a14 = b(14)
test.a15 = b(15)
test.a16 = b(16)
test.a17 = b(17)
test.a18 = b(18)
test.a19 = b(19)
test.a20 = b(20)
test.a21 = b(21)
test.a22 = b(22)
test.a23 = b(23)
test.a24 = b(24)
test.a25 = b(25)
test.a26 = b(26)
test.a27 = b(27)
test.a28 = b(28)
test.a29 = b(29)
test.a30 = b(30)
test.a31 = b(31)
test.a32 = b(32)
test.a33 = b(33)
test.a34 = b(34)
test.a35 = b(35)
test.a36 = b(36)
test.a37 = b(37)
test.a38 = b(38)
PUT #1, 1, test
CLOSE

My QB is a little rusty, but I think you need to put a colon before the REM to tell the interpreter that it isn’t part of the prior statement. i.e.

nm AS STRING * 3 : REM &lt;&lt;&lt;test.nm defined here

You don’t use the name in your type construct (test) as a data area. Add a line “dim record as test” then fill the fields “record.nm”, “record.exc”, etc.


   Dim Record as Test
   Z$ = "~~~"
   Record.nm = Z$
   Record.exc = b(1)
   .
   .

See if that doesn’t fix the problem.

Jim

The type mismatch has nothing to do with the string, it’s cause you didn’t declare a variable of type test.

So after your test decleration, you need to define a variable.

Dim foo as test

Also, instead of filling in that array, and then filling in that type, why don’t you write the data to the file as loop through? That’d get rid of the messy Test type and make a lot more sense. Unless it’s a requirement for the class.

Thanks, I kind of figured that out (it’s amazing what a little sleep will do) but my real problem was doing something exactly like an example in the book that comes with QuickBasic did it, I copied Microsoft’s mistake, although I seemed to have picked and marked the one example in the book where they did it wrong, because looking at other examples in the book, they got it right.

I really should have known better and stuck to the QuickBasic Bible from the Waite group. I think the books that come (or at least used to come in the old days) with Microsoft products are solely designed to force you to buy more books. Even so, the QuickBasic Bible and the Basic Handbook both gave examples where they defined a variable type as one word (for example “planets”) then later in the program, amongst a bunch of REMs and other statements, definded the variable (as, in this case, “DIM planet AS planets”) which, in my sleep deprived state, I would have stood a much better chance of noticing.

Why does every programming book insist on giving a complete program (in this case one to put the statistics of planets into a data file and retrieve them) that you will never use insted of giving a clear concise example of how to use the function?