Connect with us

QBasic syntax error?

Discussion in 'Electronic Basics' started by Bill Bowden, Dec 21, 2012.

Scroll to continue with content
  1. Bill Bowden

    Bill Bowden Guest

    Why does QBasic give me a syntax error with this code?


    DATA 0,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,2 '11100001011100


    WHILE TI < 2 AND INKEY$ = ""


    IF TI = 0 THEN

    IF I = 0 AND P = 1 THEN PRINT "1";
    IF I = 1 AND P = 1 THEN PRINT "0";
    P = P + 1
    IF P = 2 THEN P = 0

    END IF

    IF TI = 1 THEN

    I = I + 1
    IF I = 2 THEN I = 0
    IF I = 0 THEN PRINT "0";
    IF I = 1 THEN PRINT "1";

    END IF


    IF P = 0 THEN END
    IF I = 1 THEN PRINT "0" ELSE PRINT "1"

  2. Jon Kirwan

    Jon Kirwan Guest

    Comments aren't permitted on DATA statements, memory serving.
    When I get a moment, I'll double check that detail, though.

  3. Guest

    Yeah, then you can chase a latent bug a week and be just like
  4. Bingo! Kill the comment.

    George H.
  5. Hmm... C tends to be more dangerous when used by the ignorant.

    petrus bitbyter
  6. Now, now... for 'we bears of very little brain'* basic is a fine
    I've got several little programs that help me on my way.

    GOSUB nitpick

    All in good fun :^)
    Hey there's this white fluffy stuff falling outside my window.
    What's that?
    And here's wishing all the SEBers a wonderful Holiday season!
    I'm cutting out early to go decorate Xmas cookies at granma's with the

    George H.

    SUB nitpick
    basic doesn't need line numbers anymore
    the commands are still in caps, but I use lower case for variables
    which makes it easier to read.
    Robbie the Robot (a nice Asimov story.) was not on the screen with
    Will Robinson. (Undoubtedly the worst Sci-fi series ever!)

    *no insult intended for other basic users.
  7. Jon Kirwan

    Jon Kirwan Guest

    Yeah, I went off and installed XP mode and then dragged my
    entire Microsoft development environment (VBDOS, QB45,
    QBASIC, QC2, ML/MASM, and a bunch of other "old tools") over
    from an old machine and set up something I could test with.
    Needed to do that, anyway. And yes, I did a quick test with
    and without the comments and it worked without and didn't
    work with.

    This goes back to the 1970's, by the way. I used the original
    Microsoft papertape BASIC (which I may still have in
    papertape form if you can believe it) and had been "shocked"
    that comments on DATA statements caused it to have parsing
    problems. I was used to (1) languages that didn't support
    comments, such as HP 2000F BASIC, and (2) languages which had
    no problem with dealing with comments on DATA statements -- I
    believe it was on a PDP-10, but memory is vague now. But I'd
    never experienced one that couldn't handle something it

    I just figured that Microsoft's BASIC treated a DATA
    statement almost like a REM statement -- it didn't parse it
    or anything. It just accepted ANYTHING you typed there. It
    was "your problem" and not theirs, what you did. Only at
    run-time did it check and parse things. And since it was
    nothing more than a keyword followed by unchecked text, they
    took the easy way out and didn't bother supporting comment

    Still holds with their later tools, I see.

  8. Bill Bowden

    Bill Bowden Guest

    I forget to mention the code works ok with Borland Turbo Basic. I did
    find that adding an extra '2' to the data list fixes the problem so it
    runs right in QBasic. I'm just wondering why I need an extra data
    character in one case and not the other?

  9. I've got QB45 installed. I run half a dozen programs.
    It runs in this little minimalist screen resolution, which is kinda
    quaint, reminds me of grad school.

    George H.
  10. There's talk of a foot or more of snow. But I'll believe it when I
    see it. (I like the snow.)

    George H.
  11. I ordered a copy of power basic for $50, on someone's recommendation
    (James A.?)
    I haven't written anything in it yet though.

    George H.
  12. Jon Kirwan

    Jon Kirwan Guest

    QB45 will run with 50 lines, if you want. If you set the DOS
    box properties so that it starts with 50 lines, then QB will
    use it. If not, QB45 will still be able to use 50 lines, but
    you have to write a few lines of code then to force the line

  13. Jon Kirwan

    Jon Kirwan Guest

    Because QBASIC doesn't accept comments. Borland most
    certainly does, by comparison.

  14. Bill Bowden

    Bill Bowden Guest

    I don't think the comments are the problem. In one case with Turbo
    Basic the line reads "DATA
    0,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,2 '11100001011100"

    In the second case with QBasic, the line reads "DATA
    0,0,0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,2,2 '11100001011100 "

    All I did was add an extra 2 which fixed the problem. But looking at
    the code, the extra 2 at the end is not needed, but QBasic says it is.

  15. Jasen Betts

    Jasen Betts Guest

    qbasic is reading "2 'comment" as the last data value and can't
    interperet that as a number.

    Adding an extra datum stops it from looking at the last data value.
  16. Jon Kirwan

    Jon Kirwan Guest

    Comments are the problem. I went through a bunch of trouble
    to set up a VM with a 32-bit Virtual XP and then copy all my
    QBASIC stuff over from an older machine to try it out after
    posting my response.

    It was pretty easy to test. I didn't use just your code. I
    used some I wrote, too, just to be absolutely sure.

    No comments on DATA statements in QBASIC. The documentation
    even mentions it: "A remark can be inserted on a line after
    an executable statement if it is preceded by the single-quote
    form of REM or if REM is preceded by a colon." Note the use
    of "executable statement" in the above description. DATA is
    not an executable statement.

    Besides. I tried a lot of different ways to check this out.
    You can't do it. Check it out yourself. It will actually read
    up the comment, if you try using a string variable instead of
    a numeric one. It is NOT a comment on a DATA statement. It is
    part of the data, like it or not.

  17. Bob Masta

    Bob Masta Guest

    On Fri, 21 Dec 2012 10:23:31 -0800 (PST), George Herold

    Robbie the Robot was from "Forbidden Planet", which was a
    classic sci-fi version of Shakespeare's "The Tempest".
    Robbie appeared in numerous other movie and TV productions
    over the years. (Regarding "The Tempest" / "Forbidden
    Planet", Michael Crichton also "borrowed" the same basic
    "creatures from the id" theme for "Sphere".)

    Best regards,

    Bob Masta

    DAQARTA v7.10
    Data AcQuisition And Real-Time Analysis
    Scope, Spectrum, Spectrogram, Sound Level Meter
    Frequency Counter, Pitch Track, Pitch-to-MIDI
    FREE Signal Generator, DaqMusic generator
    Science with your sound card!
  18. Cool, I'll give it a try.

    George H.
  19. Oops, my fault I was thinking of Robbie

    George H.
  20. Wow.. OK, apparently I screwed up too. All I can say is that Asimov's
    Robbie (sans Robot) dates to 1939.

    I never knew there were so many...
    Oh it's just the 'hammer' I'm comfortable with.
    Thanks, we had a great time at granma's, another family with twin boys
    always joins us. They're six now, nothing like a pair of six year old
    to spice up the evening! I parked myself in a corner with a beer and
    enjoyed the show.

    George H.
    Wow.. OK, apparently I screwed up too. All I can say is that Asimov's
    Robbie (sans Robot) dates to 1939.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day