QB64 Phoenix Edition
I have learned something new: how to get a run-time syntax error - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: I have learned something new: how to get a run-time syntax error (/showthread.php?tid=3077)



I have learned something new: how to get a run-time syntax error - TDarcos - 09-25-2024

In the following code

Code: (Select All)
Dim a As Integer
On Error GoTo Error1

Read a
Read b

Print a
Print b
End

Dim As Integer ER, EL
Error1:
ER = Err: EL = _ErrorLine
Resume Quit



Quit:
Print "?Error"; ER; " on line"; EL; "described as "
Print _ErrorMessage$(ER)
End

Data 6
Data 7        ' the number

It will trap with an error 2 on line 5. I discovered something today:
You can't put a comment on a data statement.
Without the comment it works just fine.


RE: I have learned something new: how to get a run-time syntax error - SMcNeill - 09-25-2024

You can.   You just need to separate it with a colon first.

Code: (Select All)
DATA 7: ' this is a comment

The issue you're seeing is that you're trying to read a string as a number, and that's the run-time error.

For example:

Code: (Select All)
DATA Hello World, Steve is Awesome, Steve's the best!

That's perfectly valid data, with three data entries.  QBASIC doesn't require DATA to be inside quotes, so the "Hello World" is one string, the comma is the delimiter, "Steve is Awesome" is a second string, the comma is the delimiter, "Steve's the best!" is the third string.


DATA considers ' to be a perfectly valid part of your data.   It doesn't know "7  ' this is a comment" is a comment and only 7 is data.  How could it tell that apart from "6' 3" tall"?

Add the colon in there, and it'll run properly for you, with no issues.


RE: I have learned something new: how to get a run-time syntax error - TDarcos - 10-02-2024

(09-25-2024, 04:36 PM)SMcNeill Wrote: The issue you're seeing is that you're trying to read a string as a number, and that's the run-time error.
For example:
Code: (Select All)
DATA Hello World, Steve is Awesome, Steve's the best!
That's perfectly valid data, with three data entries.  QBASIC doesn't require DATA to be inside quotes, so the "Hello World" is one string, the comma is the delimiter, "Steve is Awesome" is a second string, the comma is the delimiter, "Steve's the best!" is the third string.
DATA considers ' to be a perfectly valid part of your data.   It doesn't know "7  ' this is a comment" is a comment and only 7 is data.  How could it tell that apart from "6' 3" tall"?
Add the colon in there, and it'll run properly for you, with no issues.
"'I see,' said the blind man, as he picked up his hammer and saw."

A data statement only needs quotes if you're going to have anything not part of that string following it, or you want to keep leading and/or trailing blanks. Like this:
Code: (Select All)

Read A, A$
Print A; A$
Read A, A$
Print A; A$
Read A, A$
Print A; A$
Read A, A$
Print A; A$
End
Data 6,A string
Data 6,"A string"
Data 6,"        A string"
Data 6,A string  'And more of the same

The third one is the only one that had leading blanks, and the 4th one took everything after the comma as the datum.

Nothing like writing a program and submitting it to the compiler for its final, infallible opinion.

To paraphrase a saying a Supreme Court justice used to describe the organization,
"The compiler's opinion is not final because it is infallible, it is infallible because it is (unless you want to rewrite parts of the compiler) final."