• QBasic program problem

    Author
    Topic
    #489795

    I still use an old DOS program-creating application called QBasic.
    I recently had to update one of the programs I use, but when I tested
    it when I considered it updated, it gave me a couple problems that for the
    life of me I cannot figure out why, and what remedy needs to be used to
    get the updated program to work again without an error.
    It has to do with a SELECT CASE code series. I have an input file of certain
    dollar values that I post into an Array and into individual variables. The
    Select Case code lines, for the most part, work. I have a CASE ELSE statement
    at the end of two of the CASE segments that end the program if “bad input”
    figures are encountered.
    I searched diligently for why this was occurring, but I was sure the input data
    used was good and should have passed muster. After not being able to find out
    the cause, I commented out the two CASE ELSE lines of code. Now the program
    works like I expected. I don’t feel like I am likely to include any input data that
    won’t be acceptable, so I am not concerned about having commented out these
    two lines of code. I just feel like every contingency should be programed for.
    Can any QBasic adept lounger give me a clue on why this is happening.

    flavet

    Viewing 8 reply threads
    Author
    Replies
    • #1398270

      I haven’t seen Qbasic in use for about 20 years and have long forgotten the syntax.
      Can you post the problematic lines and we will see if the dinosaurs come out. ;-0)

      cheers, Paul

      • #1398642

        I haven’t seen Qbasic in use for about 20 years and have long forgotten the syntax.
        Can you post the problematic lines and we will see if the dinosaurs come out. ;-0)

        cheers, Paul

        The Dinosaurs are here: QB64 is a FREE QBasic compiler for 64 bit WIN, MAC and LINUX : http://www.QB64.net

        Contrary to popular beliefs, QB64 offers everything that a C compiler can do. If you haven’t seen Qbasic being used in 20 years then you gave it up only 2 years after it was last released…

        Your code problem was most likely a file read error or the lack of UCASE$ or LCASE$ when checking strings.

    • #1398336

      Paul,

      Sorry to take so long to reply, but I am not very well versed in using this forum. I searched through the help items on how to attach a segment of program code for you to view, but the best I could find was an item about making a file and then clicking on a paperclip icon.

      Here is some of the code from the QBasic program I am having trouble with. It starts with 2 lines of comments and goes to the CLOSE statement.
      I did a copy & paste process to acquire the code you see. I’m not sure how much you can get from seeing this, but let me describe what the input
      statements consist of:
      Here is a sample line of text that you might see in the input file:
      12,A, 17850 ,maximum income 1st tax bracket
      The first two char’s are an ‘Item ID Prefix”, the next one char is an ‘Item ID Suffix’, the third field is a dollar amount, and the final field is a comment field.
      Each item is separated by a comma. The first three fields are used by the program, but the fourth is not, it is merely a remark for me to know what the line is.

      The CASE 12 items and the CASE 10 segments are the ones giving me the problem. See the single apostrophy char on the two CASE ELSE statements in
      the two Cases. That means to the program interpreter that those lines are commented out.
      Hope you are able to make sense out this without being able to see the entire program listing, or a least more of the details related to this code segment.

      Here are the program code lines:
      ‘acquire tax-year’s constant & certain variable data from stored file
      ‘also value certain array elements & other variables
      s.ifile.1 = s.fnmprefx + s.tax.yr + “CNST.DAT”
      OPEN s.ifile.1 FOR INPUT AS #1
      DO UNTIL EOF(1)
      INPUT #1, i.idp, s.ids, l.value, s.remark
      SELECT CASE i.idp
      CASE 12
      SELECT CASE s.ids ‘value array2 elements
      CASE “A”: l.array2(2, 1) = l.value ‘tax bracket max inc figs
      CASE “B”: l.array2(3, 1) = l.value
      CASE “C”: l.array2(4, 1) = l.value
      CASE “D”: l.array2(5, 1) = l.value
      CASE “E”: l.array2(6, 1) = l.value
      CASE “F”: l.array2(7, 1) = l.value
      CASE “G”: l.array2(8, 1) = l.value
      CASE “K”: l.array2(2, 2) = l.value ‘tax bracket min tax figs
      CASE “L”: l.array2(3, 2) = l.value
      CASE “M”: l.array2(4, 2) = l.value
      CASE “N”: l.array2(5, 2) = l.value
      CASE “O”: l.array2(6, 2) = l.value
      CASE “p”: l.array2(7, 2) = l.value
      CASE “S”: l.array2(1, 3) = l.value ‘tax bracket tax rates
      CASE “T”: l.array2(2, 3) = l.value
      CASE “U”: l.array2(3, 3) = l.value
      CASE “V”: l.array2(4, 3) = l.value
      CASE “W”: l.array2(5, 3) = l.value
      CASE “X”: l.array2(6, 3) = l.value
      CASE “Y”: l.array2(7, 3) = l.value
      ‘ CASE ELSE: PRINT “Bad tax rate data, abending”: CLOSE : END
      END SELECT
      CASE 1, 2, 15, 22: l.array1(i.idp, VAL(s.ids)) = l.value
      ‘N O T E – array1 rows 4-6 store tax payment amounts
      CASE 61, 62: l.array1(i.idp – 57, VAL(s.ids)) = l.value
      CASE 10
      SELECT CASE s.ids
      CASE “A”: l.xmptrte1 = l.value
      CASE “B”: l.trigger1 = l.value
      CASE “C”: l.xmptions = l.value
      CASE “D”: l.trigger2 = l.value
      CASE “E”: l.xmptrte2 = l.value
      CASE “F”: l.divisor1 = l.value
      CASE “G”: l.percent1 = l.value
      ‘ CASE ELSE: PRINT “Bad exemption data, abending”: CLOSE : END
      END SELECT
      CASE 18
      SELECT CASE s.ids
      CASE “A”: l.trigger3 = l.value
      CASE “B”: l.percent2 = l.value
      CASE ELSE: PRINT “Bad net investment data, abending”: CLOSE : END
      END SELECT
      CASE 7: FOR i = 1 TO i.prd: l.array1(i.idp, i) = l.value: NEXT
      CASE 34, 35: l.array7(i.idp – 33, VAL(s.ids)) = l.value
      CASE 41, 42: l.arrayC(i.idp – 40, VAL(s.ids)) = l.value: CG = true
      CASE 51: l.arrayD(1, VAL(s.ids)) = l.value
      CASE 52: l.arrayE(1, VAL(s.ids)) = l.value
      CASE 70: l.pytax = l.value
      END SELECT
      LOOP
      CLOSE

      Edit Post comment: I notice that all the lines of code have been rearranged to left align the text. The program lines are nicely indented.

      • #1398339

        Just looked at my QBasic files from 1995, phew! I even used CASE as well, but can’t remember in detail how they work. However, in e.g. VBA (Visual Basic for Access) there is an option to step through the program and inspect values as you go. Is there not such an option with QBasic? This is how I debug VBA. I note you don’t say what the error is – or at least I can’t see it if you do. Can you say what error messages are generated?

        Just Googled and there appears to be a Qbasic compiler – see http://www.softpedia.com/get/Programming/Coding-languages-Compilers/Qbasic.shtml, which has a debug option.

        Eliminate spare time: start programming PowerShell

        • #1398344

          Thank you, access-mdb,

          I will check out the link you posted later, but let me answer your questions first. I believe that you can single step through QBasic, but I have never had to employ that facility. Please note that my code requires that if QBasic runs into data it finds unacceptable for reasons only known by it, I have built in the CASE ELSE statement that the program should end at that point. Since QB does not give a clue as to what it finds unacceptable the programmer is left to try to figure out why on his own. I have always been successful in finding what my code errors have been, but this time I am stumped. This program worked for years for me but I had to do some updates because of changing rules by the IRS. I had to add one additional CASE detail statement to each those two CASE ## items. Then I needed to add an additional row to the dimensioning specification. That has always been a gripe of mine – can’t find out the underlying problem; it just says there is a problem so fix it. I am sure that there may be an error message that is generated, but it usually does not provide any why.
          Because I commented out the two CASE ELSE statements the program now works and it works correctly. So whatever QBasic does not like does not seem to be something I need be concerned with. I would like to find out what the underlying problem is but if I can’t, so be it.

          • #1398375

            CALL OFF THE CAVALRY! I decided to retest the latest version of my program (the one that did not work because of two CASE ELSE statements, that I commented out in order to allow the program to go to a good end.). I opened it and decided I wanted to see exactly what error message the program had given me originally. So I uncommented the two offending statements and restarted the program. Lo and behold, today it worked as I originally wanted it to work. I don’t know why, but I am not going to brood over it. I am just going to be happy with the way it is working.

            So I want to thank those who replied to my post. For access-mdb: I went to the software site and read what I could about what they offered. I may download it someday. Thanks.

            flavet

            oops – while previewing this reply I noticed, Paul, your latest posting. As I said above for some reason the program decided to work without any further updating. Thank you for your interest in my problem, and your suggestions.

            • #1398593

              In case the problem comes back, I’d just like to point out that in the code you provided, the case 12 is doing a check on lower case ‘p’, not upper case ‘P’. All the other data checks are on upper case, so I would assume that this probably should be as well. If you have data with upper case P, that will fall through to the case else and end the program unexpectedly.

            • #1398597

              Dancing – great catch! These tired old 83 year old eyes just don’t cut the mustered anymore. The reason why the original problem seemed to go away is because I was not using input files that included the Case P data. That was part of the updates I had to add, but which were outside the range of the input data.
              Regardless, great catch because I would have needed to have the correct ‘case’ (upper) for the CASE when I correlate the actual input data at a later time this year. I went back and updated this item, so now that will not be a problem in the future.
              Thank you.

            • #1398623

              Hello flavet
              Good to see good old QBasic still in general use. We still have quite a number of programs here, originally written in Quickbasic, but now I have made use of FreeBasic which is a great version of BASIC, compatible with QBasic, but will produce executables. It does also have a companion IDE called fbide which can be downloaded with the compiler. I would thoroughly recommend it. FreeBasic does also expand on the functionality of QBasic so is well worth looking at.
              Regards
              RV

    • #1398373

      I can’t see why the CASE ELSE statements should cause problems, except that they terminate the file read unexpectedly.
      From your code it seems the program exits if the ‘Item ID Suffix’ is either H, I, J, Q, R, Z or a non letter. I’d create a test file that doesn’t cause an exception and test with the CASE ELSE lines in place.

      p.s. The icons at the top of the edit window allow you to post special text. Use the key word CODE for code posts.

      Code:
      SELECT CASE i.idp
      	CASE 12
      		SELECT CASE s.ids ‘value array2 elements
      			CASE “A”: l.array2(2, 1) = l.value ‘tax bracket max inc figs
      
    • #1398636

      robV – thanks for your reply. I am not as skilled in a lot of the underlying structure as I would like to be. I have been retired for 21 years and away from any programming except for my own use. I seem to recall that program creation involved things like compilers and interpreters. I felt pushed to get the job done and don’t bother ‘us’ with your questions. When I find something that works I may use it, and not investigate what it takes to make it work beyond the obvious. I don’t even recall the term IDE, and when I tried searching for a definition on google it said no matches found.
      I don’t plan on moving into anything different at my age, I will just keep using what I know. I do thank you for your reply; it was very interesting to know that so much is out there for the asking.
      Best wishes, flavet

    • #1398658

      Don’t forget the old stand by method where you print the value of the variable before the CASE statement followed by an input statement. This effectively prints the value in question and stops execution of the program while it waits for some type of entry. ‘The old fashioned approach to debugging ;)’.

      • #1398689

        Thanks to one and all that have replied to my original post. I don’t always understand what is being said in the replies, but if I wanted to know anything I ask what is meant.
        I have used various self-created QBasic programs for my own use (regularly) and they always satisfy my needs. If, when I am creating or updating a program of this type and I make a logic error or a syntax error I have always been able to correct the problem when I test the program. I will be sticking with the software I have been using until it no longer works, or until I no longer work.
        Thanks everyone.

    • #1398702

      @flavet – good for you.

      I noticed nobody gave you a definition for IDE. If you still haven’t found it yourself, it means Integrated Development Environment and what that means is that it allows you to edit code in an editor that will colour highlight your code based on what kind a of coding thing it is (example: variables will be a different colour than keywords). But wait – that’s not all you get … usually an IDE will also show you syntax errors while you type the code – you don’t need to run it first (this might be the biggest reason to use an IDE). Sometimes they can offer suggestions to fix the error. They also often offer auto-completion. When you start typing something they offer possible completions to whatever you just typed. Usually they allow you to “debug” code by letting you execute it one line at a time, or all the lines up to a certain point, view the values of variables while the program is paused, etc.

      Anyway, as you say – if you are happy then no need to change. Some IDEs are pretty easy to learn, others can have real learning curve.

      Jim

      • #1398708

        What “CASE ELSE:” does is if the field in the input does not contain a letter in the list above CASE ELSE: then it does what follows CASE ELSE:.

        It is just another way of saying “if”. CASE ELSE: just uses a list, if just checks one thing.

        Unnoticed that the letter p is lower case, all the rest are upper case. QBasic IS case sensitive.

        Someone mentioned 83 year old eyes – try for 87. My QBasis is ancient.

    • #1398735

      Again, thanks one and all.

      @JavaJim – That is really nice to know. I appreciate your passing that along. I hope I can save all the replies I have received on this issue.


      @anon
      – Ancient or not, if it works who cares! That’s my motto.

      • #1398795

        Very interesting thread! Brought back good memories. I’m not quite 83, not even that reversed, but close to the latter. I spent many years having fun programming in gwbasic, yes, before even qbasic, on an old computer that was given to us. Loved it!

        My first adventure into qbasic was the example programs gorilla and snake (or something like that!)
        This thread made me smile! Glad to see people still using it!
        John

    • #1398961

      I just fired up QB and right on the menu line is a debug menu. You can have it stop on any line (breakpoint) just before execution, trace 1 line at a time, set a watchpoint that when a variable changes to a specified criteria (including greater than (+or equal to), less than (+or equal to), equal to, not equal to), the program will stop. If you use the HELP > Contents > Run & Debug Keys, it lists all the debug tools and shortcut keys.

    • #1399180

      @cpusrvc – Thank you for your reply. I knew about these debugging facilities, but I don’t recall ever employing them. I stated earlier that the errors I encountered during my coding were usually quickly noted and just as quickly corrected. This time I was really stumped (and you could say I still am since the program with the problem running to EOJ just seemed to work later on). The CASE case (as in lower/upper case) probably didn’t come into play because I had not yet created a ‘P’ input value. Anyway, thank you for your information. I didn’t realize there were so many ‘dinosaurs’ that visited this particular forum.

    Viewing 8 reply threads
    Reply To: QBasic program problem

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: