### Author Topic: "Illegal string-number conversion"  (Read 291 times)

#### QootyKev

• Jr. Member
• Posts: 86
##### "Illegal string-number conversion"
« on: August 19, 2011, 07:40:06 AM »
I'm sorry I must be daft. This code worked in QBasic, but not in QB64.

Here is the code at the start of this utility :

Code: [Select]
`10 COLOR 7, 0   LOCATE 1, 1   A\$(0) = "x"   A\$(1) = CHR\$(251)   B\$(1) = "*"   B\$(2) = " "20 M = 130 OPEN "DATA\DEFAULT.STP" FOR INPUT AS #1LoadSetupData:40  INPUT #1, Z\$    if eof(1)=0 then input #1, Cmd\$50 CLOSE60 FOR T = 1 TO 470    A(T) = VAL(MID\$(Z\$, T, 1))80 NEXT90 FOR T = 1 TO 4100    B(T) = VAL(MID\$(Z\$, T + 4, 1))110 NEXT120 FOR T = 1 TO 3130    C(T) = VAL(MID\$(Z\$, T + 8, 1))140 NEXT150 FOR T = 1 TO 7160    D(T) = VAL(MID\$(Z\$, T + 11, 1))170 NEXT180 FOR T = 1 TO 2190    E(T) = VAL(MID\$(Z\$, T + 18, 1))200 NEXT210 FOR T = 1 TO 2220    F(T) = VAL(MID\$(Z\$, T + 20, 1))230 NEXT240 FOR T = 1 TO 2250    G(T) = VAL(MID\$(Z\$, T + 22, 1))260 NEXT`
A screenshot of error message is at : http://img846.imageshack.us/img846/5176/qb64error.png
Maybe this will also work :
(http://img846.imageshack.us/img846/5176/qb64error.png)

It still looks ok to me ...

Kev

#### Gorlock

• Sr. Member
• Posts: 337
##### Re: "Illegal string-number conversion"
« Reply #1 on: August 19, 2011, 07:50:14 AM »
I can't test it because I am missing "DATA\DEFAULT.STP", but the problem seemed to be the arrays you were using. I don't really know why maybe someone else could explain it. But I did fix it for you:

Code: [Select]
`COLOR 7, 0LOCATE 1, 1A\$(0) = "x"A\$(1) = CHR\$(251)B\$(1) = "*"B\$(2) = " "M = 1OPEN "DATA\DEFAULT.STP" FOR INPUT AS #1LoadSetupData:INPUT #1, Z\$IF EOF(1) = 0 THEN INPUT #1, Cmd\$CLOSE #1FOR t = 1 TO 4    p(t) = VAL(MID\$(Z\$, t, 1))NEXT tFOR t = 1 TO 4    h(t) = VAL(MID\$(Z\$, t + 4, 1))NEXT tFOR t = 1 TO 3    i(t) = VAL(MID\$(Z\$, t + 8, 1))NEXT tFOR t = 1 TO 7    j(t) = VAL(MID\$(Z\$, t + 11, 1))NEXT tFOR t = 1 TO 2    k(t) = VAL(MID\$(Z\$, t + 18, 1))NEXT tFOR t = 1 TO 2    l(t) = VAL(MID\$(Z\$, t + 20, 1))NEXT tFOR t = 1 TO 2    m(t) = VAL(MID\$(Z\$, t + 22, 1))NEXT t`

#### QootyKev

• Jr. Member
• Posts: 86
##### Re: "Illegal string-number conversion"
« Reply #2 on: August 19, 2011, 07:56:45 AM »
Heh sorry, yeah the contents of the default setup file was a string of text, namely (in this case) : "011010000011000000100010"

I also thought it may have been to do with the arrays, as mine are not dimensioned and the variables do not specify whether integer etc.

In my case, I want to be able to convert my utility from Qbasic to QB64, without having to rebuild from the ground up.

Thanks for the fix you have put forward, if I can just ask for some clarity, all I have seen you do is replace the letters used as variable labels, with different letters. Is that all you did? I wonder why that could possibly make a difference!

Thanks again. Now I just have to find out why what I have doesn't work.

#### Gorlock

• Sr. Member
• Posts: 337
##### Re: "Illegal string-number conversion"
« Reply #3 on: August 19, 2011, 08:06:55 AM »
Also, when you want to close a file you have open I usually use CLOSE #<file handle> (example: CLOSE #1), as it is more specific and helps if you have more than 1 file open.

Also I don't think it is just the type of variable, the default is Integer, I think had something to do with the paticular name of them. It was also a problem for A(t) and B(t). I couldn't even do this:

q = VAL(MID\$(Z\$, t, 1))
A(t) = q

That also returned an error, so it was somethig with those two names.

#### QootyKev

• Jr. Member
• Posts: 86
##### Re: "Illegal string-number conversion"
« Reply #4 on: August 19, 2011, 08:15:05 AM »
Hmm I wonder if its related to the use of A\$ and B\$ up the top.

I might see what happens if I change those instead.

Thanks again!

EDIT: Yep, that fixed it! QB64 was basically screaming "Which ******* one do you mean?" and throwing punches at me.
« Last Edit: August 19, 2011, 08:21:39 AM by QootyKev »

#### Galleon

• Hero Member
• Posts: 4664
• QB Forever
##### Re: "Illegal string-number conversion"
« Reply #5 on: August 19, 2011, 04:58:19 PM »
A bug in QB64 was causing this problem. It'll be fixed in the next release. Thanks for raising the issue. Clippy has submitted a bug report for you.
Something old... Something new... Something borrowed... Something blue...

#### QootyKev

• Jr. Member
• Posts: 86
##### Re: "Illegal string-number conversion"
« Reply #6 on: August 20, 2011, 07:11:40 AM »
Thanks Galleon! I always just assume it must be my own ignorance and not a bug haha!