Computer Science Canada help with calling record |
Author: | ejoman3002 [ Thu Apr 19, 2007 2:04 pm ] |
Post subject: | help with calling record |
hey. im making a phone book program for class and i need help. basicly im making a phone book program and 1 of the options i put is if the user wants to look up the persons info by whatever info they choose. such as if they wana look up someone whos name is bob. but they also have the option to search by last name, address, phone numbers..... so on. so the code to do that looks like this on my program Quote: if search="first name" then put" whats the persons first name" get search2 for decreasing i:friendnum..1 if search2=info(i).firstname then infogive (i) end if end for i want firstname in "info(i).firstname" to be changable. so if the user wants to search by there last name first name would change to the last name variable. so that i dont need to make a new if statement for each of the options they search by. problem is that when i type "info(i).option (option being a variable set by the user. so if they want to search by first name option would=firstname or by house number option would=homenum) it doesnt read option as a variable. is there any way to do it. basicly i want it to act something like this should but wont act Quote: if search="first name" then option:=firstname elsif option="last name" then option:=lastname elsif option="home phone" then option:=homenum elsif option="cell phone" then option:=homenum end if put "whats the persons ", option get search2 for decreasing i:friendnum..1 %friendnum is the number of friends the user wants to enter in the phone book if search2=info(i).option then infogive (i) end if end for |
Author: | rollerdude [ Fri Apr 20, 2007 10:19 am ] | ||||
Post subject: | Re: help with calling record | ||||
well, you have it set up so that option tells you what to look by, when in your for statment, you told the program to see if "Fred", for example, = "firstname", which always return false. you have to set it up to look in the array for "Fred" in your record do you have it set up like: Edited by Clayton: Remember your code/syntax tags children!
kinda? what if you dont use an option, but rather, to have something like
you get the idea maybe this might help? |
Author: | ejoman3002 [ Fri Apr 20, 2007 11:46 am ] | ||
Post subject: | Re: help with calling record | ||
that is what iv done. basically looks like this
this works but i want a more effiecient way of doing it. something that wont take up so much lines of code. i dont like it this way. |