Board Logo
« code has some problems »

Welcome Guest. Please Login or Register.
Nov 21st, 2009, 9:21pm



Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ

Please use the forums Search feature before asking. For best results select only the categories, which describe your need best.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is to long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.
To register at the Just BASIC Files Archive Site, please follow the instructions given in File Archives - Important Registration Information.

Pages: 1  Notify Send Topic Print
 thread  Author  Topic: code has some problems  (Read 114 times)
tubeparker
New Member
Image

member is offline

Avatar




PM


Posts: 10
xx code has some problems
« Thread started on: Nov 7th, 2009, 03:22am »

I am having some more issues with this code. A few of the lines aren't working correctly. remarks with "(doesn't work)" are the lines I am currently having issues with. The problems are that when "A" is pressed in [homeScreen], instead of going to [about], it goes to [addCategory]. Also, when an amount is entered, it displays the [noAmount] message. When I press enter to go back to enter amount, it goes to [addCategory]. I hope you understood all that. Please help. Thanks!
Code:
dim nameCat$(15)
dim amount(15)

[homeScreen]'title screen or menu
    cls
    print "Budget Planner v1.0"
    print
    print "Press 'Enter' to Continue (ALT + F4 to Exit)"
    print "Press 'A' to goto About Budget Planner v1.0"'suppose to goto about(doesn't work)
    input "";a
    goto [addCategory]

[addCategory]'adds category to array
    cls
    print "Category Name:";
    input "";catName$
    if catName$="" then [noCat]
    if nameCat$(index)="" then nameCat$(index)=catName$: goto [catConfirm]
    index=index+1

    print "Limit of Categories Reached"
    goto [homeScreen]

[addAmount]'adds amount to array (doesn't work)
    cls
    print "Enter Category Amount: "
    input "";catAmount
    if catAmount=0 then [noAmount]
    index=index+1
    amount(index)=catAmount

[catConfirm]'user confirms category entered is correct
    cls
    print "You entered";" ";"'";catName$;"'"
    print "Is this correct(Y/N)?"
    input "";catConfirm$
    if instr("YESyes",catConfirm$)>0 then goto[catSuccess]
    goto [addCategory]

[amountConfirm]'user confirms amount entered is correct
    cls
    print "You entered";" "; using("#####.##",catAmount+0.001)
    print "Is this correct(Y/N)?"
    input "";amountConfirm
    if instr("YESyes",catAmount)>0 then [amountSuccess]

[noAmount]'displays when no amount is entered
    cls
    print "Sorry, you did not enter an amount!"
    print "Please go back."
    print
    print "Press 'Enter' to go back (ALT + F4 to exit)"
    input "";a
    goto [addAmount]

[noCat]'displays when no category is entered
    cls
    print "Sorry, you did not enter a category!"
    print "Please go back."
    print
    print "Press 'Enter' to go back (ALT +F4 to exit)"
    input "";a
    goto [addCategory]

[catSuccess]'displays when category is correctly entered and confirmed
    cls
    print "'";catName$;"'";" ";"added successfully!"
    print
    print "Press 'Enter' to add";" ";catName$;"'s amount."
    input "";a
    goto [addAmount]

[amountSuccess]'displays when amount entered is correctly entered and confirmed
    cls
    print using("#####.##", catAmount+0.001);" ";"added successfully"
    print
    print "Add another category(Y/N)?"
    input "";anotherCat
    if instr("YESyes",anotherCat)>0 then [addCategory]

[full]'displays when array is full
    cls
    print "No more entries can be made!"
    print "Press 'Enter' to return to title"
    print "or ALT + F4 to exit."
    input "";a
    goto [homeScreen]

[about]'displays budget planner info
    cls
    print "Budget Planner v1.0 is a program"
    print "designed to track finances."
    print "Built by: Christopher Parker"
    print "Built using: Just Basic"
    print "Press 'H' to return to menu."
    input "";home
    if instr("Hh",home)>0 then [homeScreen]
 

Also, it would be great if someone can tell me if there is a way to link the two arrays together, so that when displayed, the category and that categories amount will show. If you get what I mean.
« Last Edit: Nov 7th, 2009, 03:25am by tubeparker » User IP Logged

Psycho
Member in Training
ImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 26
xx Re: code has some problems
« Reply #1 on: Nov 7th, 2009, 08:58am »

tubeparker,

I'll hit your first question to get you started.
In this part of your code
Code:
[homeScreen]'title screen or menu
    cls
    print "Budget Planner v1.0"
    print
    print "Press 'Enter' to Continue (ALT + F4 to Exit)"
    print "Press 'A' to goto About Budget Planner v1.0"'suppose to goto about(doesn't work)
    input "";a
    goto [addCategory]
 

you ask the user to press 'A' to go to about but after the input "";a statement, you aren't checking for how they responded so the program simply falls into the [addCategory] branch.
In addition, you are asking for an alpha response "A" but have a numeric variable "a" which should be changed to a$. After that change, you need to check if the user pressed "A" and if so, then go to the [about] branch.
In your [about] branch you do check for the user pressing "H" so you can use similar code but that input also needs to be changed to a string variable (home$ instead of home)

Hope this helps.

**EDIT**
BTW, "home" is a reserved word used as a graphic command so I would avoid using it as a variable name.

John "Psycho" Siejkowski
« Last Edit: Nov 7th, 2009, 10:27am by Psycho » User IP Logged

tubeparker
New Member
Image

member is offline

Avatar




PM


Posts: 10
xx Re: code has some problems
« Reply #2 on: Nov 7th, 2009, 1:46pm »

It did help but you still left out one part.
Also, when an amount is entered, it displays the [noAmount] message. When I press enter to go back to enter amount, it goes to [addCategory]. See if you can run it yourself to understand what I mean. Thank you! smiley

Actually what its doing is after entering the category amount, it is going to the branch label right after it, which is [catConfirm] instead of going to [amountConfirm]
« Last Edit: Nov 7th, 2009, 1:58pm by tubeparker » User IP Logged

Stefan Pendl
Administrator
ImageImageImageImageImage

member is offline

Avatar

Let's talk JB ...


PM

Gender: Male
Posts: 2158
xx Re: code has some problems
« Reply #3 on: Nov 7th, 2009, 2:46pm »

You will have to tell your program what to decide in which situation.

I would run the program step-by-step through the debugger to see, why it goes wrong.

You are missing many IF..THEN conditions as described by Psycho, so your program just falls through to the next portion and does not branch as expected.

The use of numerical variables, where string variables are expected is the other problem.
User IP Logged

Stefan

Any code I post can be used by others in their own projects, there is no need to ask for permission, just give credit if you like

Just BASIC 1.01, Windows Vista Home Premium SP2, AMD Turion X2 RM-70 2GHz, 4GB RAM
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ


New Monthly Ad-Free Plan!

$6.99 Gets 50,000 Ad-Free Pageviews!
| Free Shoutboxes | Hookah |

This Board Hosted For FREE By Conforums ©
Get Your Own Free Message Board!