Author Topic: Monthly Budget Maker  (Read 5249 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Monthly Budget Maker
« on: February 10, 2021, 09:07:42 pm »
I know these have been made 1000's of times by people, but I've never made a complete one like this before. It asks you basic budget questions about different bills and your income, etc. Then it calculates how much extra money you will have left. It doesn't ask some extra question items like clothes and restaurants, but you can add them on the last question if you wish, under "Anything Else". This program also saves your information to a .txt file under a name of your choosing and you can open it with this program anytime too. Upon opening an existing file, it also asks if you want to print it on paper to your printer. I hope this helps some of you out there. I had fun making it. Put it in its own folder so the files it makes won't get lost. If you have comments or suggestions, please reply, thanks.

Code: QB64: [Select]
  1. 'This program can create monthly budgets for your home.
  2. 'It saves the files as .txt files and can also open and print them to the printer.
  3. 'I hold no responsibility for any errors, money loss, or damage from using this program, so use at your own risk.
  4. 'It has been tested a few times by me and works really well.
  5. 'Made on February 10, 2021 by SierraKen.
  6.  
  7. _TITLE "Monthly Budget Maker"
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. start:
  10. start2:
  11. a = 0
  12. PRINT "                                       Monthly Budget Maker"
  13. PRINT "                                    (1) Create a new budget."
  14. PRINT "                                    (2) Open an existing budget."
  15. PRINT "                                    (3) End Program"
  16. PRINT "                                    ----------------------------"
  17. INPUT "                                    ->", a
  18. IF a > 3 OR a < 1 OR a <> INT(a) THEN GOTO start:
  19. IF a = 1 THEN GOTO makefile:
  20. IF a = 2 THEN GOTO openfile:
  21. IF a = 3 THEN END
  22. openfile:
  23. INPUT "Type name of existing file to open (without .txt ending): ", f$
  24. f$ = f$ + ".txt"
  25.     PRINT
  26.     PRINT f$; " does not exist."
  27.     PRINT
  28.     GOTO start2:
  29.  
  30. FOR lines = 1 TO 23
  31.     INPUT #1, text$
  32.     PRINT text$
  33.     IF EOF(1) THEN GOTO skip:
  34. NEXT lines
  35. skip:
  36. INPUT "Do you want to print this to your printer (Y/N): ", printer$
  37. IF LEFT$(printer$, 1) = "y" OR LEFT$(printer$, 1) = "Y" THEN GOTO printing:
  38. GOTO finished:
  39. printing:
  40. FOR lines = 1 TO 23
  41.     INPUT #1, text$
  42.     LPRINT text$
  43.     IF EOF(1) THEN GOTO skip2:
  44. NEXT lines
  45. skip2:
  46. finished:
  47. printer$ = ""
  48. INPUT "Press Enter to go back to Main Menu."; menu$
  49. GOTO start:
  50.  
  51. makefile:
  52. PRINT "Answer the following questions."
  53. INPUT "Year: "; y$
  54. INPUT "Month: "; m$
  55. INPUT "Total Monthly Income: "; income
  56. INPUT "Rent or Home Payment Amount: "; rent
  57. INPUT "Health Total (health insurance / medication / etc.): "; health
  58. INPUT "Credit Card Payments: "; creditcard
  59. INPUT "Home or Renters Insurance: "; homeinsurance
  60. INPUT "Driver's Insurance: "; driversinsurance
  61. INPUT "Other Insurance Total (life insurance / etc.): "; otherinsurance
  62. INPUT "Grocery Store Amount (food and all other items.): "; food
  63. INPUT "Laundry Quarters (if any): "; laundry
  64. INPUT "Heating Gas (if different than electric bill): "; heating
  65. INPUT "Electricity: "; electricity
  66. INPUT "Phone (and Internet if connected to phone bill.): "; phone
  67. INPUT "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  68. INPUT "Vehicle Gas: "; gas
  69. INPUT "Haircut or Hairstyle: "; hair
  70. INPUT "Savings: "; savings
  71. INPUT "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  72. total = rent + health + creditcard + homeinsurance + driversinsurance + otherinsurance + food + laundry + heating + electricity + phone + TV + gas + hair + savings + anythingelse
  73. leftover = income - total
  74. PRINT "Extra Money: "; leftover
  75. file:
  76. INPUT "(S)ave or (M)ain Menu: ", save$
  77. IF LEFT$(save$, 1) = "m" OR LEFT$(save$, 1) = "M" THEN GOTO start:
  78. IF LEFT$(save$, 1) = "s" OR LEFT$(save$, 1) = "S" THEN GOTO saving:
  79. GOTO file:
  80. saving:
  81. INPUT "Type name of .txt file to save it as (without the .txt ending): ", filename$
  82. filename$ = filename$ + ".txt"
  83. IF _FILEEXISTS(filename$) THEN
  84.     PRINT filename$, " already exists, overwrite (Y/N):";
  85.     INPUT o$
  86.     IF LEFT$(o$, 1) = "y" OR LEFT$(o$, 1) = "Y" THEN GOTO save:
  87.     GOTO file:
  88. save:
  89. OPEN filename$ FOR OUTPUT AS #1
  90. PRINT #1, "Year: "; y$
  91. PRINT #1, "Month: "; m$
  92. PRINT #1, "Total Monthly Income: "; income
  93. PRINT #1, "Rent or Home Payment Amount: "; rent
  94. PRINT #1, "Health Total (health insurance / medication / etc.): "; health
  95. PRINT #1, "Credit Card Payments: "; creditcard
  96. PRINT #1, "Home or Renters Insurance: "; homeinsurance
  97. PRINT #1, "Driver's Insurance: "; driversinsurance
  98. PRINT #1, "Other Insurance Total (life insurance / etc.): "; otherinsurance
  99. PRINT #1, "Grocery Store Amount (food and all other items.): "; food
  100. PRINT #1, "Laundry Quarters (if any): "; laundry
  101. PRINT #1, "Heating Gas (if different than electric bill): "; heating
  102. PRINT #1, "Electricity: "; electricity
  103. PRINT #1, "Phone (and Internet if connected to phone.): "; phone
  104. PRINT #1, "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  105. PRINT #1, "Vehicle Gas: "; gas
  106. PRINT #1, "Haircut or Hairstyle: "; hair
  107. PRINT #1, "Savings: "; savings
  108. PRINT #1, "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  109. PRINT #1, "------------------------------------------------------------------------------"
  110. PRINT #1, "Extra Money: "; leftover
  111. PRINT #1, "----------------------"
  112. PRINT filename$; " has been saved."
  113. INPUT "Press Enter to go back to Main Menu."; menu$
  114. GOTO start:
  115.  


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #1 on: February 10, 2021, 10:13:31 pm »
You're my GOTO guy, which is my smart ascii way of encouraging you to code without those GOTO statements. That way, you can go big with your ideas, without the debugging problems GOTO will inevitably cause. Can you ever use GOTO to an advantage, and without problems? Sure, but you'd be surprised how easy they are to avoid most of the time. For instance, I'm in the middle of a WP project, which is 5,400 lines so far and none of those lines need or use a GOTO statement. DO/EXIT DO/LOOP can replace most of them, even the more complex ones. EXIT SUB and a flag to recall the SUB is another way around them. Using GOSUB / RETURN and a more modular approach helps, too.

It's just my hunch that you will be expanding on this or similar input applications, and if so, I'd love to see you utilize more of the structural components, mentioned above.

For instance...

Code: QB64: [Select]
  1. FOR lines = 1 TO 23
  2.     INPUT #1, text$
  3.     PRINT text$
  4.     IF EOF(1) THEN GOTO skip:
  5. NEXT lines
  6. skip:

Could be written as...

Code: QB64: [Select]
  1. FOR lines = 1 TO 23
  2.     LINE INPUT #1, text$
  3.     PRINT text$
  4.     IF EOF(1) THEN EXIT FOR

That works faster and provided you have one or more files, the EXIT FOR can remain where it is.

All of this...

Code: QB64: [Select]
  1. start:
  2. start2:
  3. a = 0
  4. PRINT "                                       Monthly Budget Maker"
  5. PRINT "                                    (1) Create a new budget."
  6. PRINT "                                    (2) Open an existing budget."
  7. PRINT "                                    (3) End Program"
  8. PRINT "                                    ----------------------------"
  9. INPUT "                                    ->", a
  10. IF a > 3 OR a < 1 OR a <> INT(a) THEN GOTO start:
  11. IF a = 1 THEN GOTO makefile:
  12. IF a = 2 THEN GOTO openfile:
  13. IF a = 3 THEN END
  14. openfile:
  15. INPUT "Type name of existing file to open (without .txt ending): ", f$
  16. f$ = f$ + ".txt"
  17.     PRINT
  18.     PRINT f$; " does not exist."
  19.     PRINT
  20.     GOTO start2:
  21.  
  22. FOR lines = 1 TO 23
  23.     INPUT #1, text$
  24.     PRINT text$
  25.     IF EOF(1) THEN GOTO skip:
  26. NEXT lines
  27. skip:
  28. INPUT "Do you want to print this to your printer (Y/N): ", printer$
  29. IF LEFT$(printer$, 1) = "y" OR LEFT$(printer$, 1) = "Y" THEN GOTO printing:
  30. GOTO finished:
  31. printing:
  32. FOR lines = 1 TO 23
  33.     INPUT #1, text$
  34.     LPRINT text$
  35.     IF EOF(1) THEN GOTO skip2:
  36. NEXT lines
  37. skip2:
  38. finished:
  39. printer$ = ""
  40. INPUT "Press Enter to go back to Main Menu."; menu$
  41. GOTO start:

Could be enclosed in a loop:

Code: QB64: [Select]
  1. start2:
  2. a = 0
  3. PRINT "                                       Monthly Budget Maker"
  4. PRINT "                                    (1) Create a new budget."
  5. PRINT "                                    (2) Open an existing budget."
  6. PRINT "                                    (3) End Program"
  7. PRINT "                                    ----------------------------"
  8. INPUT "                                    ->", a
  9. IF a > 3 OR a < 1 OR a <> INT(a) THEN GOTO start:
  10. IF a = 1 THEN GOTO makefile:
  11. IF a = 2 THEN GOTO openfile:
  12. IF a = 3 THEN END
  13. openfile:
  14. INPUT "Type name of existing file to open (without .txt ending): ", f$
  15. f$ = f$ + ".txt"
  16.     PRINT
  17.     PRINT f$; " does not exist."
  18.     PRINT
  19.     GOTO start2:
  20.  
  21. FOR lines = 1 TO 23
  22.     INPUT #1, text$
  23.     PRINT text$
  24.     IF EOF(1) THEN GOTO skip:
  25. NEXT lines
  26. skip:
  27. INPUT "Do you want to print this to your printer (Y/N): ", printer$
  28. IF LEFT$(printer$, 1) = "y" OR LEFT$(printer$, 1) = "Y" THEN GOTO printing:
  29. GOTO finished:
  30. printing:
  31. FOR lines = 1 TO 23
  32.     INPUT #1, text$
  33.     LPRINT text$
  34.     IF EOF(1) THEN GOTO skip2:
  35. NEXT lines
  36. skip2:
  37. finished:
  38. printer$ = ""
  39. INPUT "Press Enter to go back to Main Menu."; menu$

And you could use GOSUBs, other loops, etc. in the code in between, to eliminate other GOTO statements.

Anyway, my bet is if you try these non-goto techniques, you'll grow to appreciate them a lot more than goto statements when you start writing larger apps of this type.

Kudos on branching out in this direction. I stick pretty close to stuff like this, but I have to admit that car game you made almost got me to break out to do something similar. That was really impressive. Sort of a Flappy Bird like app, and it made me wish QB64 worked on hand held devices.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #2 on: February 10, 2021, 10:25:00 pm »
Thanks Pete! I had a hunch someone would mention the GOTO's. :) And I had no idea that "EXIT FOR" even existed! Thank you! B+ helped me learn a lot about DO/LOOPS last year and since then almost all my QB64 programs have used those loops. But sometimes I just can't get away from some GOTO's. The big reason why I only used GOTOs in this program is because lately I've felt very nostalgic. And I made this program partly because it's something I've thought about almost all my life. So a lot of very old memories are associated with it. But I'll remember what you said for my future programs. This is still a small enough program that GOTOs won't make a difference, so I'm going to leave them like it is without tearing back into it. But I appreciate the suggestions. When I learned BASIC back in the 80's, they taught it to me like making a map in my mind, going up to down on the code and using GOTOs and GOSUBs going around and around making it the genius programming language that it still is. In my opinion anyway. But I understand nowadays computers work a lot more independent (in Windows, etc) than they used to.  So I'll try to make less GOTOs in the future.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #3 on: February 10, 2021, 10:38:20 pm »
Well, I changed my mind somewhat. Pete I took your advice and made it one big loop and added the EXIT FOR's. I also removed an unneeded DELAY.  I might be able to add more loops and things within the main LOOP but at least this is a little better, you think? :)

Code: QB64: [Select]
  1. 'This program can create monthly budgets for your home.
  2. 'It saves the files as .txt files and can also open and print them to the printer.
  3. 'I hold no responsibility for any errors, money loss, or damage from using this program, so use at your own risk.
  4. 'It has been tested a few times by me and works really well.
  5. 'Made on February 10, 2021 by SierraKen.
  6.  
  7. _TITLE "Monthly Budget Maker"
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9.     start:
  10.     CLS
  11.     start2:
  12.     a = 0
  13.     PRINT "                                       Monthly Budget Maker"
  14.     PRINT: PRINT
  15.     PRINT "                                    (1) Create a new budget."
  16.     PRINT "                                    (2) Open an existing budget."
  17.     PRINT "                                    (3) End Program"
  18.     PRINT "                                    ----------------------------"
  19.     PRINT
  20.     INPUT "                                    ->", a
  21.     IF a > 3 OR a < 1 OR a <> INT(a) THEN GOTO start:
  22.     IF a = 1 THEN GOTO makefile:
  23.     IF a = 2 THEN GOTO openfile:
  24.     IF a = 3 THEN END
  25.     openfile:
  26.     CLS
  27.     PRINT: PRINT
  28.     INPUT "Type name of existing file to open (without .txt ending): ", f$
  29.     f$ = f$ + ".txt"
  30.     IF _FILEEXISTS(f$) = 0 THEN
  31.         PRINT
  32.         PRINT f$; " does not exist."
  33.         PRINT
  34.         GOTO start2:
  35.     END IF
  36.  
  37.     OPEN f$ FOR INPUT AS #1
  38.     FOR lines = 1 TO 23
  39.         INPUT #1, text$
  40.         PRINT text$
  41.         IF EOF(1) THEN EXIT FOR
  42.     NEXT lines
  43.     CLOSE #1
  44.     PRINT: PRINT
  45.     INPUT "Do you want to print this to your printer (Y/N): ", printer$
  46.     IF LEFT$(printer$, 1) = "y" OR LEFT$(printer$, 1) = "Y" THEN GOTO printing:
  47.     GOTO finished:
  48.     printing:
  49.     CLS
  50.     OPEN f$ FOR INPUT AS #1
  51.     FOR lines = 1 TO 23
  52.         INPUT #1, text$
  53.         LPRINT text$
  54.         IF EOF(1) THEN EXIT FOR
  55.     NEXT lines
  56.     CLOSE #1
  57.     finished:
  58.     PRINT: PRINT
  59.     INPUT "Press Enter to go back to Main Menu."; menu$
  60.     GOTO start:
  61.  
  62.     makefile:
  63.     CLS
  64.     PRINT: PRINT
  65.     PRINT "Answer the following questions."
  66.     PRINT: PRINT
  67.     INPUT "Year: "; y$
  68.     INPUT "Month: "; m$
  69.     INPUT "Total Monthly Income: "; income
  70.     INPUT "Rent or Home Payment Amount: "; rent
  71.     INPUT "Health Total (health insurance / medication / etc.): "; health
  72.     INPUT "Credit Card Payments: "; creditcard
  73.     INPUT "Home or Renters Insurance: "; homeinsurance
  74.     INPUT "Driver's Insurance: "; driversinsurance
  75.     INPUT "Other Insurance Total (life insurance / etc.): "; otherinsurance
  76.     INPUT "Grocery Store Amount (food and all other items.): "; food
  77.     INPUT "Laundry Quarters (if any): "; laundry
  78.     INPUT "Heating Gas (if different than electric bill): "; heating
  79.     INPUT "Electricity: "; electricity
  80.     INPUT "Phone (and Internet if connected to phone bill.): "; phone
  81.     INPUT "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  82.     INPUT "Vehicle Gas: "; gas
  83.     INPUT "Haircut or Hairstyle: "; hair
  84.     INPUT "Savings: "; savings
  85.     INPUT "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  86.     CLS
  87.     PRINT
  88.     PRINT
  89.     total = rent + health + creditcard + homeinsurance + driversinsurance + otherinsurance + food + laundry + heating + electricity + phone + TV + gas + hair + savings + anythingelse
  90.     leftover = income - total
  91.     PRINT "Extra Money: "; leftover
  92.     file:
  93.     PRINT: PRINT
  94.     INPUT "(S)ave or (M)ain Menu: ", save$
  95.     IF LEFT$(save$, 1) = "m" OR LEFT$(save$, 1) = "M" THEN GOTO start:
  96.     IF LEFT$(save$, 1) = "s" OR LEFT$(save$, 1) = "S" THEN GOTO saving:
  97.     GOTO file:
  98.     saving:
  99.     INPUT "Type name of .txt file to save it as (without the .txt ending): ", filename$
  100.     filename$ = filename$ + ".txt"
  101.     IF _FILEEXISTS(filename$) THEN
  102.         PRINT filename$, " already exists, overwrite (Y/N):";
  103.         INPUT o$
  104.         IF LEFT$(o$, 1) = "y" OR LEFT$(o$, 1) = "Y" THEN GOTO save:
  105.         GOTO file:
  106.     END IF
  107.     save:
  108.     OPEN filename$ FOR OUTPUT AS #1
  109.     PRINT #1, "Year: "; y$
  110.     PRINT #1, "Month: "; m$
  111.     PRINT #1, "Total Monthly Income: "; income
  112.     PRINT #1, "Rent or Home Payment Amount: "; rent
  113.     PRINT #1, "Health Total (health insurance / medication / etc.): "; health
  114.     PRINT #1, "Credit Card Payments: "; creditcard
  115.     PRINT #1, "Home or Renters Insurance: "; homeinsurance
  116.     PRINT #1, "Driver's Insurance: "; driversinsurance
  117.     PRINT #1, "Other Insurance Total (life insurance / etc.): "; otherinsurance
  118.     PRINT #1, "Grocery Store Amount (food and all other items.): "; food
  119.     PRINT #1, "Laundry Quarters (if any): "; laundry
  120.     PRINT #1, "Heating Gas (if different than electric bill): "; heating
  121.     PRINT #1, "Electricity: "; electricity
  122.     PRINT #1, "Phone (and Internet if connected to phone.): "; phone
  123.     PRINT #1, "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  124.     PRINT #1, "Vehicle Gas: "; gas
  125.     PRINT #1, "Haircut or Hairstyle: "; hair
  126.     PRINT #1, "Savings: "; savings
  127.     PRINT #1, "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  128.     PRINT #1, "------------------------------------------------------------------------------"
  129.     PRINT #1, "Extra Money: "; leftover
  130.     PRINT #1, "----------------------"
  131.     CLOSE #1
  132.     PRINT filename$; " has been saved."
  133.     PRINT: PRINT
  134.     INPUT "Press Enter to go back to Main Menu."; menu$
  135.  
« Last Edit: February 10, 2021, 10:42:13 pm by SierraKen »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #4 on: February 11, 2021, 02:16:05 am »
Or no GOTOs...

Code: QB64: [Select]
  1. _TITLE "Monthly Budget Maker"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.     CLS
  4.     WHILE -1
  5.         a = 0
  6.         PRINT "                                       Monthly Budget Maker"
  7.         PRINT: PRINT
  8.         PRINT "                                    (1) Create a new budget."
  9.         PRINT "                                    (2) Open an existing budget."
  10.         PRINT "                                    (3) End Program"
  11.         PRINT "                                    ----------------------------"
  12.         PRINT
  13.         INPUT "                                    ->", a
  14.         SELECT CASE a
  15.             CASE 1
  16.                 GOSUB makefile
  17.                 GOSUB file: IF flag% THEN flag% = 0: EXIT WHILE
  18.             CASE 2
  19.                 GOSUB openfile: IF flag% THEN flag% = 0: EXIT WHILE
  20.             CASE 3
  21.                 END
  22.             CASE ELSE
  23.                 EXIT WHILE
  24.         END SELECT
  25.     WEND
  26.  
  27. '----------------------------------------------------------------------------
  28. file:
  29.     PRINT: PRINT
  30.     INPUT "(S)ave or (M)ain Menu: ", save$
  31.     IF LCASE$(LEFT$(save$, 1)) = "m" THEN flag% = -1: EXIT DO
  32.     IF LCASE$(LEFT$(save$, 1)) = "s" THEN GOSUB saving: IF flag% THEN EXIT DO
  33.  
  34. makefile:
  35. PRINT "Answer the following questions."
  36. INPUT "Year: "; y$
  37. INPUT "Month: "; m$
  38. INPUT "Total Monthly Income: "; income
  39. INPUT "Rent or Home Payment Amount: "; rent
  40. INPUT "Health Total (health insurance / medication / etc.): "; health
  41. INPUT "Credit Card Payments: "; creditcard
  42. INPUT "Home or Renters Insurance: "; homeinsurance
  43. INPUT "Driver's Insurance: "; driversinsurance
  44. INPUT "Other Insurance Total (life insurance / etc.): "; otherinsurance
  45. INPUT "Grocery Store Amount (food and all other items.): "; food
  46. INPUT "Laundry Quarters (if any): "; laundry
  47. INPUT "Heating Gas (if different than electric bill): "; heating
  48. INPUT "Electricity: "; electricity
  49. INPUT "Phone (and Internet if connected to phone bill.): "; phone
  50. INPUT "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  51. INPUT "Vehicle Gas: "; gas
  52. INPUT "Haircut or Hairstyle: "; hair
  53. INPUT "Savings: "; savings
  54. INPUT "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  55. total = rent + health + creditcard + homeinsurance + driversinsurance + otherinsurance + food + laundry + heating + electricity + phone + TV + gas + hair + savings + anythingelse
  56. leftover = income - total
  57. PRINT "Extra Money: "; leftover
  58.  
  59. openfile:
  60. INPUT "Type name of existing file to open (without .txt ending): ", f$
  61. f$ = f$ + ".txt"
  62.     OPEN f$ FOR INPUT AS #1
  63.     FOR lines = 1 TO 23
  64.         INPUT #1, text$
  65.         PRINT text$
  66.         IF EOF(1) THEN EXIT FOR
  67.     NEXT lines
  68.     CLOSE #1
  69.     PRINT: PRINT
  70.     INPUT "Do you want to print this to your printer (Y/N): ", printer$
  71.     ' Printing
  72.     IF LCASE$(LEFT$(printer$, 1)) = "y" THEN
  73.         CLS
  74.         OPEN f$ FOR INPUT AS #1
  75.         FOR lines = 1 TO 23
  76.             INPUT #1, text$
  77.             LPRINT text$
  78.             IF EOF(1) THEN EXIT FOR
  79.         NEXT lines
  80.         CLOSE #1
  81.     END IF
  82.     ' finished
  83.     PRINT: PRINT
  84.     INPUT "Press Enter to go back to Main Menu."; menu$
  85.     flag% = -1
  86.     PRINT
  87.     PRINT f$; " does not exist."
  88.     PRINT
  89.  
  90. saving:
  91. INPUT "Type name of .txt file to save it as (without the .txt ending): ", filename$
  92. filename$ = filename$ + ".txt"
  93. IF _FILEEXISTS(filename$) THEN
  94.     PRINT filename$, " already exists, overwrite (Y/N):";
  95.     INPUT o$
  96.     IF LCASE$(LEFT$(o$, 1)) = "y" THEN GOSUB save
  97.     GOSUB save
  98.  
  99. save:
  100. OPEN filename$ FOR OUTPUT AS #1
  101. PRINT #1, "Year: "; y$
  102. PRINT #1, "Month: "; m$
  103. PRINT #1, "Total Monthly Income: "; income
  104. PRINT #1, "Rent or Home Payment Amount: "; rent
  105. PRINT #1, "Health Total (health insurance / medication / etc.): "; health
  106. PRINT #1, "Credit Card Payments: "; creditcard
  107. PRINT #1, "Home or Renters Insurance: "; homeinsurance
  108. PRINT #1, "Driver's Insurance: "; driversinsurance
  109. PRINT #1, "Other Insurance Total (life insurance / etc.): "; otherinsurance
  110. PRINT #1, "Grocery Store Amount (food and all other items.): "; food
  111. PRINT #1, "Laundry Quarters (if any): "; laundry
  112. PRINT #1, "Heating Gas (if different than electric bill): "; heating
  113. PRINT #1, "Electricity: "; electricity
  114. PRINT #1, "Phone (and Internet if connected to phone.): "; phone
  115. PRINT #1, "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  116. PRINT #1, "Vehicle Gas: "; gas
  117. PRINT #1, "Haircut or Hairstyle: "; hair
  118. PRINT #1, "Savings: "; savings
  119. PRINT #1, "Anything Else (church / house labor / babysitter / schools / etc.): "; anythingelse
  120. PRINT #1, "------------------------------------------------------------------------------"
  121. PRINT #1, "Extra Money: "; leftover
  122. PRINT #1, "----------------------"
  123. PRINT filename$; " has been saved."
  124. INPUT "Press Enter to go back to Main Menu."; menu$
  125. flag% = -1
  126.  
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #5 on: February 11, 2021, 01:05:54 pm »
WOW! Thanks Pete! I'm learning from yours. Yours will also be the best version I believe, unless I add anything later to it. I've only used CASE a couple times so I need to get used to it. Thanks again.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #6 on: February 11, 2021, 01:58:54 pm »
Question 1: Is it harder or easier now to see what the code is doing? If it's easier, you could go even further into modular modifications.  The goal being, to create a program flow so intuitive, any debugging or future additions and/or modifications could be done in an instant.

I still struggle with the above. What I find is the more conditional statements and shared subs and functions that come into existence, the harder it is to keep the program flow straight. Some methods that help are...

Keep the main part short and use sub calls or gosubs for the heavy work.

so...

Menu
GOSUB menu
GOSUB menu actions
ON menuactions$ GOSUB dothis, dothat, doall, etc
GOSUB finish

I've also found that, although it takes using conditional variables, or flags, it is easier to keep flow understandable when using subs, if you can finish a sub without having it call another sub, which then might call yet another sub.

In sever cases of thousands of lines of code with hundreds of conditions, I've considered keeping segments independent, meaning each module preforms a complete task without sharing sub calls or gosubs; however, that would mean repeating a lot of code. Back in QB days, that would put you out of business in a hurry, but without those old QB memory limits, who cares how big the program is? Sure, it would be more code to read, but understanding it would b a lot easier. There is one draw back. If you modify a block of code that has the same code in another block, you have to remember to modify both. Now cut and paste works great for that, but sometimes conditions present where the code needs to be slightly different in each block, as modifications often create added conditions. So the next time you need to modify the program, you have to make sure you do not forget what looks like the same block of code is no longer the same. See? Keeping it simple, is simply not SIMPLE!!!!!!

Anyway, yeah, I was hoping you'd like to try out some stuff, because I really feel you will be making a lot more stuff, and this should make those future projects easier. I grew up in those GOTO and line number days, too, but nostalgia aside, I don't miss them.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #7 on: February 11, 2021, 02:41:21 pm »
Awesome Pete. Yep I had a couple of those code segments in this program, using almost the same lines, except a little different on each one. 1. Inputting the needed code to make a budget. 2. Print #1 outputting the same code to save the budget. 3. and LPRINTING the same lines to print it on the printer. The other one, Inputting and PRINTING the already made budget just used a FOR/NEXT loop using the right amount of text lines from the file. If me or anyone else adds any budget questions, they just have to add the number of more lines to the FOR/NEXT loop.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #8 on: February 11, 2021, 03:17:56 pm »
My trick for additions is to put the info into a DATA statement. Want to add or subtract more budget items, now you just type those entries to that DATA. You can go a step further and make it a database. Now you don't ever have to mess with the source code to modify the number of budget items, just append the database file, usually in Notepad. So what about the FOR/NEXT loop? Just have the program count the number of data entries when it starts, and set a variable like noe (number of entries) to that result. Now we just code it as...

FOR i = 1 to noe

Oh, it helps to end the DATA statement with EOD (end of data. I'll do an example, but I think you already know this, but just in case...

Also if you want to go that route, you now have arrays. So now instead of all of those print statements, all you need is another loop, which prints the next array!

So you get something like...

Code: QB64: [Select]
  1. noe = 0
  2. RESTORE mydata
  3.     READ a$
  4.     IF a$ = "EOD" THEN EXIT DO
  5.     noe = noe + 1
  6. REDIM item$(noe), itemValue(noe)
  7. RESTORE mydata
  8. i = 0
  9.     READ a$
  10.     IF a$ = "EOD" THEN EXIT DO
  11.     i = i + 1
  12.     item$(i) = a$
  13.  
  14. FOR i = 1 TO noe
  15.     PRINT item$(i);: INPUT itemValue(i)
  16.  
  17. FOR i = 1 TO noe
  18.     total = total + itemValue(i)
  19. PRINT total
  20.  
  21. mydata:
  22. DATA item-1
  23. DATA item-2
  24. DATA item-3
  25. DATA EOD
  26.  

Anyway, food for thought.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #9 on: February 11, 2021, 03:53:54 pm »
Thanks! Yeah I could have done it that way with the .txt files. Just add an EOD at the end of the text file and look for it in a loop. Although, I do use the EOF(1) command too, which pretty much does the same thing I think, although I haven't used it much. Lots of things to play around with now. :)

Marked as best answer by SierraKen on February 11, 2021, 11:47:54 am

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #10 on: February 11, 2021, 04:47:15 pm »
I decided to add Internet bill if separate from everything else, water and sewer, trash, housework, church, babysitter, school(s), and total of anything else. I didn't number a FOR/NEXT loop and just did DO/LOOPs with EOF(1) to break the loops.

Code: QB64: [Select]
  1. _TITLE "Monthly Budget Maker"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.     CLS
  4.     WHILE -1
  5.         a = 0
  6.         PRINT "                                       Monthly Budget Maker"
  7.         PRINT: PRINT
  8.         PRINT "                                    (1) Create a new budget."
  9.         PRINT "                                    (2) Open an existing budget."
  10.         PRINT "                                    (3) End Program"
  11.         PRINT "                                    ----------------------------"
  12.         PRINT
  13.         INPUT "                                    ->", a
  14.         SELECT CASE a
  15.             CASE 1
  16.                 GOSUB makefile
  17.                 GOSUB file: IF flag% THEN flag% = 0: EXIT WHILE
  18.             CASE 2
  19.                 GOSUB openfile: IF flag% THEN flag% = 0: EXIT WHILE
  20.             CASE 3
  21.                 END
  22.             CASE ELSE
  23.                 EXIT WHILE
  24.         END SELECT
  25.     WEND
  26.  
  27. '----------------------------------------------------------------------------
  28. file:
  29.     PRINT: PRINT
  30.     INPUT "(S)ave or (M)ain Menu: ", save$
  31.     IF LCASE$(LEFT$(save$, 1)) = "m" THEN flag% = -1: EXIT DO
  32.     IF LCASE$(LEFT$(save$, 1)) = "s" THEN GOSUB saving: IF flag% THEN EXIT DO
  33.  
  34. makefile:
  35. PRINT "Answer the following questions."
  36. INPUT "Year: "; y$
  37. INPUT "Month: "; m$
  38. INPUT "Total Monthly Income: "; income
  39. INPUT "Rent or Home Payment Amount: "; rent
  40. INPUT "Health Total (health insurance / medication / etc.): "; health
  41. INPUT "Credit Card Payments: "; creditcard
  42. INPUT "Home or Renters Insurance: "; homeinsurance
  43. INPUT "Driver's Insurance: "; driversinsurance
  44. INPUT "Other Insurance Total (life insurance / etc.): "; otherinsurance
  45. INPUT "Grocery Store Amount (food and all other items.): "; food
  46. INPUT "Laundry Quarters (if any): "; laundry
  47. INPUT "Heating Gas (if different than electric bill): "; heating
  48. INPUT "Electricity: "; electricity
  49. INPUT "Phone (and Internet if connected to phone bill.): "; phone
  50. INPUT "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  51. INPUT "Internet if it's a separate bill: "; internet
  52. INPUT "Vehicle Gas: "; gas
  53. INPUT "Water and Sewer bill (add together if separate): "; water
  54. INPUT "Trash bill: "; trash
  55. INPUT "Housework: "; housework
  56. INPUT "Church: "; church
  57. INPUT "Babysitter: "; babysitter
  58. INPUT "School(s): "; schools
  59. INPUT "Haircut or Hairstyle: "; hair
  60. INPUT "Savings: "; savings
  61. INPUT "Total of anything else: "; anythingelse
  62. total = rent + health + creditcard + homeinsurance + driversinsurance + otherinsurance + food + laundry + heating + electricity + phone + TV + internet + gas + water + trash + housework + church + babysitter + schools + hair + savings + anythingelse
  63. leftover = income - total
  64. PRINT "Extra Money: "; leftover
  65.  
  66. openfile:
  67. INPUT "Type name of existing file to open (without .txt ending): ", f$
  68. f$ = f$ + ".txt"
  69.     OPEN f$ FOR INPUT AS #1
  70.     DO
  71.         INPUT #1, text$
  72.         PRINT text$
  73.         IF EOF(1) THEN EXIT DO
  74.     LOOP
  75.     CLOSE #1
  76.     PRINT: PRINT
  77.     INPUT "Do you want to print this to your printer (Y/N): ", printer$
  78.     ' Printing
  79.     IF LCASE$(LEFT$(printer$, 1)) = "y" THEN
  80.         CLS
  81.         OPEN f$ FOR INPUT AS #1
  82.         DO
  83.             INPUT #1, text$
  84.             LPRINT text$
  85.             IF EOF(1) THEN EXIT DO
  86.         LOOP
  87.         CLOSE #1
  88.     END IF
  89.     ' finished
  90.     PRINT: PRINT
  91.     INPUT "Press Enter to go back to Main Menu."; menu$
  92.     flag% = -1
  93.     PRINT
  94.     PRINT f$; " does not exist."
  95.     PRINT
  96.  
  97. saving:
  98. INPUT "Type name of .txt file to save it as (without the .txt ending): ", filename$
  99. filename$ = filename$ + ".txt"
  100. IF _FILEEXISTS(filename$) THEN
  101.     PRINT filename$, " already exists, overwrite (Y/N):";
  102.     INPUT o$
  103.     IF LCASE$(LEFT$(o$, 1)) = "y" THEN GOSUB save
  104.     GOSUB save
  105.  
  106. save:
  107. OPEN filename$ FOR OUTPUT AS #1
  108. PRINT #1, "Year: "; y$
  109. PRINT #1, "Month: "; m$
  110. PRINT #1, "Total Monthly Income: "; income
  111. PRINT #1, "Rent or Home Payment Amount: "; rent
  112. PRINT #1, "Health Total (health insurance / medication / etc.): "; health
  113. PRINT #1, "Credit Card Payments: "; creditcard
  114. PRINT #1, "Home or Renters Insurance: "; homeinsurance
  115. PRINT #1, "Driver's Insurance: "; driversinsurance
  116. PRINT #1, "Other Insurance Total (life insurance / etc.): "; otherinsurance
  117. PRINT #1, "Grocery Store Amount (food and all other items.): "; food
  118. PRINT #1, "Laundry Quarters (if any): "; laundry
  119. PRINT #1, "Heating Gas (if different than electric bill): "; heating
  120. PRINT #1, "Electricity: "; electricity
  121. PRINT #1, "Phone (and Internet if connected to phone.): "; phone
  122. PRINT #1, "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "; TV
  123. PRINT #1, "Internet if it's a separate bill: "; internet
  124. PRINT #1, "Vehicle Gas: "; gas
  125. PRINT #1, "Water and Sewer bill (add together if separate): "; water
  126. PRINT #1, "Trash bill: "; trash
  127. PRINT #1, "Housework: "; housework
  128. PRINT #1, "Church: "; church
  129. PRINT #1, "Babysitter: "; babysitter
  130. PRINT #1, "School(s): "; schools
  131. PRINT #1, "Haircut or Hairstyle: "; hair
  132. PRINT #1, "Savings: "; savings
  133. PRINT #1, "Total of anything else: "; anythingelse
  134. PRINT #1, "------------------------------------------------------------------------------"
  135. PRINT #1, "Extra Money: "; leftover
  136. PRINT #1, "----------------------"
  137. PRINT filename$; " has been saved."
  138. INPUT "Press Enter to go back to Main Menu."; menu$
  139. flag% = -1
  140.  
« Last Edit: February 11, 2021, 04:49:59 pm by SierraKen »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #11 on: February 11, 2021, 07:36:13 pm »
Or, apply the DATA method, and end up with this...

Code: QB64: [Select]
  1. _TITLE "Monthly Budget Maker"
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3.  
  4. noe = 0
  5. RESTORE mydata
  6.     READ a$
  7.     IF a$ = "EOD" THEN EXIT DO
  8.     noe = noe + 1
  9. REDIM item$(noe), itemValue(noe)
  10. RESTORE mydata
  11.  
  12.     CLS
  13.     WHILE -1
  14.         a = 0
  15.         PRINT "                                       Monthly Budget Maker"
  16.         PRINT: PRINT
  17.         PRINT "                                    (1) Create a new budget."
  18.         PRINT "                                    (2) Open an existing budget."
  19.         PRINT "                                    (3) End Program"
  20.         PRINT "                                    ----------------------------"
  21.         PRINT
  22.         INPUT "                                    ->", a
  23.         SELECT CASE a
  24.             CASE 1
  25.                 GOSUB makefile
  26.                 GOSUB file: IF flag% THEN flag% = 0: EXIT WHILE
  27.             CASE 2
  28.                 GOSUB openfile: IF flag% THEN flag% = 0: EXIT WHILE
  29.             CASE 3
  30.                 END
  31.             CASE ELSE
  32.                 EXIT WHILE
  33.         END SELECT
  34.     WEND
  35.  
  36. '----------------------------------------------------------------------------
  37. file:
  38.     PRINT: PRINT
  39.     INPUT "(S)ave or (M)ain Menu: ", save$
  40.     IF LCASE$(LEFT$(save$, 1)) = "m" THEN flag% = -1: EXIT DO
  41.     IF LCASE$(LEFT$(save$, 1)) = "s" THEN GOSUB saving: IF flag% THEN EXIT DO
  42.  
  43. makefile:
  44. '------------------------------
  45. i = 0
  46.     READ a$
  47.     IF a$ = "EOD" THEN EXIT DO
  48.     i = i + 1
  49.     item$(i) = a$
  50. '------------------------------
  51. PRINT "Answer the following questions."
  52. INPUT "Year: "; y$
  53. INPUT "Month: "; m$
  54. INPUT "Total Monthly Income: "; income
  55. '----------------------------------------
  56. FOR i = 1 TO noe
  57.     PRINT item$(i);: INPUT itemValue(i)
  58. '----------------------------------------
  59. FOR i = 1 TO noe
  60.     total = total + itemValue(i)
  61. leftover = income - total
  62. PRINT "Extra Money: "; leftover
  63.  
  64. openfile:
  65. INPUT "Type name of existing file to open (without .txt ending): ", f$
  66. f$ = f$ + ".txt"
  67.     OPEN f$ FOR INPUT AS #1
  68.     DO
  69.         INPUT #1, text$
  70.         PRINT text$
  71.         IF EOF(1) THEN EXIT DO
  72.     LOOP
  73.     CLOSE #1
  74.     PRINT: PRINT
  75.     INPUT "Do you want to print this to your printer (Y/N): ", printer$
  76.     ' Printing
  77.     IF LCASE$(LEFT$(printer$, 1)) = "y" THEN
  78.         CLS
  79.         OPEN f$ FOR INPUT AS #1
  80.         DO
  81.             INPUT #1, text$
  82.             LPRINT text$
  83.             IF EOF(1) THEN EXIT DO
  84.         LOOP
  85.         CLOSE #1
  86.     END IF
  87.     ' finished
  88.     PRINT: PRINT
  89.     INPUT "Press Enter to go back to Main Menu."; menu$
  90.     flag% = -1
  91.     PRINT
  92.     PRINT f$; " does not exist."
  93.     PRINT
  94.  
  95. saving:
  96. INPUT "Type name of .txt file to save it as (without the .txt ending): ", filename$
  97. filename$ = filename$ + ".txt"
  98. IF _FILEEXISTS(filename$) THEN
  99.     PRINT filename$, " already exists, overwrite (Y/N):";
  100.     INPUT o$
  101.     IF LCASE$(LEFT$(o$, 1)) = "y" THEN GOSUB save
  102.     GOSUB save
  103.  
  104. save:
  105. OPEN filename$ FOR OUTPUT AS #1
  106. PRINT #1, "Year: "; y$
  107. PRINT #1, "Month: "; m$
  108. PRINT #1, "Total Monthly Income: "; income
  109. '------------------------------------------
  110. FOR i = 1 TO noe
  111.     PRINT #1, item$(i); itemValue(i)
  112. '------------------------------------------
  113. PRINT #1, "------------------------------------------------------------------------------"
  114. PRINT #1, "Extra Money: "; leftover
  115. PRINT #1, "----------------------"
  116. PRINT filename$; " has been saved."
  117. INPUT "Press Enter to go back to Main Menu."; menu$
  118. flag% = -1
  119.  
  120. mydata:
  121. DATA "Rent or Home Payment Amount: "
  122. DATA "Health Total (health insurance / medication / etc.): "
  123. DATA "Credit Card Payments: "
  124. DATA "Home or Renters Insurance: "
  125. DATA "Driver's Insurance: "
  126. DATA "Other Insurance Total (life insurance / etc.): "
  127. DATA "Grocery Store Amount (food and all other items.): "
  128. DATA "Laundry Quarters (if any): "
  129. DATA "Heating Gas (if different than electric bill): "
  130. DATA "Electricity: "
  131. DATA "Phone (and Internet if connected to phone bill.): "
  132. DATA "Satellite / Cable / Streaming TV (and Internet if connected to TV bill.): "
  133. DATA "Internet if it's a separate bill: "
  134. DATA "Vehicle Gas: "
  135. DATA "Water and Sewer bill (add together if separate): "
  136. DATA "Trash bill: "
  137. DATA "Housework: "
  138. DATA "Church: "
  139. DATA "Babysitter: "
  140. DATA "School(s): "
  141. DATA "Haircut or Hairstyle: "
  142. DATA "Savings: "
  143. DATA "Total of anything else: "
  144. DATA "EOD"
  145.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #12 on: February 11, 2021, 09:23:42 pm »
Oh I see what you meant, thanks. I'm pretty much finished with this program though.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Monthly Budget Maker
« Reply #13 on: February 11, 2021, 10:54:24 pm »
But you'll be missing out on all the really, really fun stuff like editing records with RA files, custom input routine, input validation, string math, input fields, screen scrolling , mouse actions, and my personal favorite, wait for it, a GUI skin with popup messages for prompts.

Well truth be told, I've made a few of the down and dirty quick service apps myself, mostly for tax purposes and some other organizational activities. I mean by the time you add all the other bells and whistles I mentioned, you'd just be getting paroled for failure to complete your taxes in a timely manner.

Well this was fun, and btw, if you want to make use of the data version, feel free to do so, meaning if you want to attach your name to it, and put it on your site, with or without any revisions, it's fine with me. Now time for me to get back to more monotonous debugging. 

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Monthly Budget Maker
« Reply #14 on: February 12, 2021, 12:45:04 am »
Thanks Pete.  But around a year ago or so I stopped my website so everything I make just goes to this forum and on my hard drive. I just program as a hobby, nothing else. :)