Computer Science Canada Database |
Author: | Jekate [ Fri Jun 22, 2007 5:57 pm ] | ||
Post subject: | Database | ||
Hello everyone. I'm having some problems with a database program I'm writing. Here is what I have so far:
Now what I am trying to do is whenever I choose to add a new user, the array size gets bigger so I can keep adding users. The program comes to a halt when it tries to print what I've entered. I'm not sure what's wrong. I get an error "Array subscript is out of range." I'm not sure what that means. Thanks for any help. |
Author: | Saad [ Fri Jun 22, 2007 6:08 pm ] | ||||||||
Post subject: | Re: Database | ||||||||
because you declared a static array you cannot change the size of the array and the number that your trying to access is out of its bounds. I would recomend reading about flexible arrays as this will provide the solution or just replace
with
with
|
Author: | Jekate [ Sat Jun 23, 2007 7:43 am ] | ||||
Post subject: | Re: Database | ||||
Alright, thanks for the help. But I am still receiving an error when it tries to print it. I can add more then 1 entry into the database, and it does print them, but when after it is finished printing is when the error occurs. This is what I have now: EDIT: Ok, I tried something and it seems to be working. I added the -1 to the
And I've added a bit more.
What I eventually want to be able to have the program do is be able to press a number, and it save the current list to a file. Also, for the program to be able to load the file, and be able to print it, as if I just entered it into the program. I also would like it so that when I add more users to the list, that it add it do the file when I save it, and not overwrite the current users in the save file. I'm not sure if that's possible but if so, that's what I'm gearing towards. Oh, and a search function. If it's possible to be able to search for either names or IP's already entered in the database, to be able to search for them and bring up that info. |
Author: | DIIST [ Sat Jun 23, 2007 9:31 am ] |
Post subject: | Re: Database |
Just use upper(ARRAY) - lower(ARRAY) commands to keep track of the number of elements in the array. As for you database you should try implementing a linklist if this is one of your own projects, not something due for school. It will be very easy with a linked list to add and delete users and even print them. |
Author: | Jekate [ Sat Jun 23, 2007 11:13 am ] |
Post subject: | Re: Database |
Okay. You're going to have to explain the upper(ARRAY) and lower(ARRAY) as well as the linked list things. I'm not sure what they are. And yes, this is something I'm doing for myself. I'm done school. |
Author: | DIIST [ Sat Jun 23, 2007 11:22 am ] | ||
Post subject: | Re: Database | ||
Jekate @ June 23rd 2007 wrote: Okay. You're going to have to explain the upper(ARRAY) and lower(ARRAY) as well as the linked list things. I'm not sure what they are. And yes, this is something I'm doing for myself. I'm done school.
As for the linked list there should be a tutorial somewhere. It should be under a pointer lesson. ![]() |
Author: | Jekate [ Sat Jun 23, 2007 1:59 pm ] | ||
Post subject: | Re: Database | ||
Ok, I'm not sure exactly how to implement the upper(array) and lower(array) yet. Are you trying to say that I can increase the size of the array with the upper(array) command? What you showed me just shows me that the upper(array) and lower(array) shows me what the limits of the array are, which I understand. But I'm not sure if I can edit these values. If so, could you explain how. I'm still looking into the linked lists. I found a tutorial here about them, but it's going to be a bit before I understand those. Thanks for the help, and here is what I've added so far. I can't load for some reason.
|
Author: | Jekate [ Sat Jun 23, 2007 4:55 pm ] | ||
Post subject: | Re: Database | ||
EDIT: Ok, I'm done. Program is finished unless I think of something later I want to add. Thanks for your help.
|
Author: | Jekate [ Sun Jun 24, 2007 12:10 am ] |
Post subject: | Re: Database |
I'm wondering if I can make my job easier by making the program query a server and retrieve a list of IP's and names. Is that even possible with turing? |
Author: | Andy [ Sun Jun 24, 2007 2:56 am ] |
Post subject: | RE:Database |
ya search up turing + php on the forums |
Author: | Jekate [ Sun Jun 24, 2007 9:37 am ] |
Post subject: | Re: Database |
Alright, I've been looking it up on forums, but not exactly sure what I need to be looking for from the search. |
Author: | d2bb [ Mon Jul 09, 2007 10:08 pm ] |
Post subject: | Re: Database |
Jekate @ Sun Jun 24, 2007 9:37 am wrote: Alright, I've been looking it up on forums, but not exactly sure what I need to be looking for from the search.
this program sound lot like a "virus". ![]() also, should have ending code of else choice not = 1-8... then put "that was not a choice." just tips ![]() |
Author: | Jekate [ Sun Jun 15, 2008 10:35 pm ] |
Post subject: | Re: Database |
Alright. Bringing back an old topic, yes I know. Anyways, I'm bored and want to expand on this program. I'm going to be looking in linked lists as stated before. Also, when I enter anything else but an integer for the choice, I get an error, how do I stop this from happening? Is there a variable that contains both strings, integers, floats, etc. that I can use? When I search for text, or an IP, I have to enter the exact string for the program to find it. How can I make it so if I search for a 3 letter string such as 'hey', that it will find anything with the string 'hey' in the word? |
Author: | Tony [ Sun Jun 15, 2008 10:42 pm ] |
Post subject: | Re: Database |
Jekate @ Sun Jun 15, 2008 10:35 pm wrote: Also, when I enter anything else but an integer for the choice, I get an error, how do I stop this from happening? Is there a variable that contains both strings, integers, floats, etc. that I can use?
A string will accept anything as a string. You can then typecast it into other types with strint(), strreal(). Make sure to check if that would actually work, with intstrok(), etc, else you might get run-time errors. |
Author: | [Gandalf] [ Mon Jun 16, 2008 12:10 am ] | ||
Post subject: | RE:Database | ||
And to find a certain substring within a string, you can use the index() function:
This will output 4. If "hey" was not in the main string, it would return 0. |
Author: | Jekate [ Thu Jul 17, 2008 9:09 pm ] |
Post subject: | Re: Database |
Alright, but that's not what I was looking for. I want to be able to search the variables and see if the word I'm searching for matches any of them or even a partial match. Let's say I search the word "the". The program should be able to find all variables with 'the' in it, whether it be just the word 'the' or any word with 'the' in it, including 'them', 'these', 'soothed', etc. I'm pretty sure this is possible. I want to be able to do it with real numbers as well, but not sure if that's possible. |
Author: | [Gandalf] [ Thu Jul 17, 2008 10:10 pm ] |
Post subject: | RE:Database |
I'm pretty sure index() will satisfy your needs... It returns a positive number if the substring is in the string, and zero otherwise. So index ("these", "the") will return 1, so you know "the" is located starting from the first letter of "these". You would use index() in a similar way with integers and real numbers, except you would have to convert them to strings first using intstr() and realstr(). Use F9 if you need help using those functions. |
Author: | Jekate [ Thu Jul 17, 2008 10:17 pm ] |
Post subject: | Re: Database |
Right, it will show me which variables it occurs in with the output, but I need to be able to see the whole variable that it was found in, not just a integer output. I don't think I explained myself well enough. Let's say I search "Matt". The program searches all the variables and outputs all the variables that it matches with. So it could output: MattSmith MattAnderson etc I need to be able to see the actual variale that it matched with. Maybe I could use something like this: If the output is greater than 0 then output the full variable. Would that work? |
Author: | Tony [ Thu Jul 17, 2008 10:22 pm ] |
Post subject: | Re: Database |
Jekate @ Thu Jul 17, 2008 10:17 pm wrote: Maybe I could use something like this: If the output is greater than 0 then output the full variable. Would that work?
Yes, that is what you are supposed to do. index() should be used in a condition, and you are expected to remember what string you were just checking against. |
Author: | Jekate [ Thu Jul 17, 2008 10:24 pm ] |
Post subject: | Re: Database |
Alright, that I can do. The string I am searchin against is a variable anyways, so I don't need to remember it. |
Author: | Jekate [ Fri Jul 18, 2008 6:26 pm ] | ||||||
Post subject: | Re: Database | ||||||
Sorry for the double post but I have another issue. As I worked on getting the search working, I came across this problem: I want the program to output "Match(s) found." whether one or many items matched the search. This is what I have so far:
Also, I was looking around on the forums and found something on parallel arrays. I was wondering if I could use this structure of coding because of how I keep declaring new sizes for my arrays. So instead of this:
This woud be used:
Could I use the same type of structure? |
Author: | Insectoid [ Fri Jul 18, 2008 7:55 pm ] | ||
Post subject: | RE:Database | ||
Sorry for just giving him the answer, guys. Basically, a record is a data type. The basic ones, string, int, real, etc. are predefined. Types allow you to make your own. The only type I have ever used (or heard of) is the record. It becomes VERY useful in databases, as you have doubtless found out. |
Author: | Jekate [ Fri Jul 18, 2008 8:37 pm ] |
Post subject: | Re: Database |
I'm not 100% sure why a record type of variable is better in a database program. A string variable accepts any input anyway. Is it because that you can work around parallel arrays? And thanks for the code, I appreciate it. |
Author: | [Gandalf] [ Fri Jul 18, 2008 8:56 pm ] | ||||||
Post subject: | RE:Database | ||||||
Well, for one, you can avoid parallel arrays, like you said. The other thing is that basically a database is a list of records, where a record is simply a group of information that means something more significant when put together. So instead of:
You would use:
Also, an alternative to the code you posted is to avoid the declaration of a new type, assuming there's only one such list of students:
|
Author: | Insectoid [ Sat Jul 19, 2008 10:10 am ] |
Post subject: | RE:Database |
Hmm, I didn't know you could do that last one. Thanks! |
Author: | Jekate [ Sat Jul 19, 2008 12:31 pm ] |
Post subject: | Re: Database |
I'm having trouble implementing this. I tried both Insectoid's and Gandalf's methods but I can't seem to get it to work. I keep getting errors telling me that the 3 variables in the record thing haven't been declared. EDIT: Ok, I think I fixed the declared variable errors, but am having other troubles. I think I can fix it though, it may just take some time. |
Author: | [Gandalf] [ Sat Jul 19, 2008 1:41 pm ] |
Post subject: | RE:Database |
No problem insectoid. ![]() Jekate, you'll have to show your code for that, but it sounds like you're just getting the syntax wrong. Try using the last two code snippets I posted as reference, just make sure to change somethings(i) to students(i). |
Author: | Jekate [ Sat Jul 19, 2008 1:44 pm ] |
Post subject: | Re: Database |
I got it working. Thanks. Now I have to add the search function talked about earlier on in this topic. I'm still stumped on how to get the "Match(es) found." only once if any match is found. Here is my code now: EDIT: Ok, I changed my code a little and figured that out. Now to continue on with the search function. EDIT: Alright, I've added the code but it's not working properly. It makes a match if I search the entire variable but it won't make a match if I search only a partial. I tested it by adding a new purchase (#1) and entered abc cba aab into the inputs, respectively. I then searched (#6) "a" and it found no matches. Here is my code as of now: EDIT: I know why, nevermind. EDIT: Yes, another edit. Now that I finished up that part of the program, I'm adding a variable to the program. The program is now a budget sort of program as you probably have noticed. Anyways, I came across a problem. I'm adding a 'balance' variable to the program. It will take the amount_subracted and subtract that from the balance to create a new balance. The problem is, right now I have amount_subtracted as a string and I need it as a real. This is obvious why. But when I do this, I can't search anymore because it can't search a real number with a string. Can I use strreal() or realstr()? If so, how? I also want to start organizing my output. Is there a way to tell how long a variable is? I remember reading somewhere that I can't use locate or cursor position in text mode so that's not really helpful. |
Author: | Jekate [ Sat Jul 19, 2008 8:55 pm ] |
Post subject: | Re: Database |
Sorry for the double post but I figured that I had enough edits on my last post. Alright what I need to figure out now is how to change my program to be able to add a 'balance' variable to my program. The balance will be a real variable, and I want to be able to subract the 'amount_subtracted' from it and get a new balance. The problem is that my balance is going to be real, and my amount_subtracted is a string. If I were to switch my amount_subtracted to a real as well, the search wouldn't work properly because it will try to find a string in a real number and it won't work. Can I use realstr() or strreal() to fix this? Also, I want to start making my program look better so I want to be able to find out how long a variable is. I can use the length() command to find out how long a string is but is there a way I can find out the lengths of other types of variables? |
Author: | [Gandalf] [ Sun Jul 20, 2008 1:03 am ] |
Post subject: | RE:Database |
Yes, you will use realstr() and strreal()... So you will choose your amount_subtracted to actually be either a real or string, and then you will convert it to the necessary type (string or real) when you need that. If you need help using those functions, use the Turing help (F9). It's the same with the length() function, you first get the variable as a string and use length() on that. Edits are good, they mean that you're figuring out the problem independently. However, you might want to have faith in your own abilities and give yourself some time to solve any problems before posting. Not that asking is bad or anything. ![]() |
Author: | Jekate [ Sun Jul 20, 2008 10:16 am ] | ||
Post subject: | Re: Database | ||
I have the length() solved for the string variables at the moment. I also looked into the strreal() and realstr() commands and I think I know how to do it now. I can also use strrealok() and realstrok(). EDIT: Alright, I've got another problem. I've changed my code so that whenever you run it, it automatically loads all the variables from the text file. But the problem now is that whenever I try to add a new purchase (option 1 in the program), it doesn't seem to store any of the information you enter into the variables. You can see this by trying to add a new purchase (option 1) and then printing the list (option 2). I have no idea. All I changed was loading the variables. Here is my code: EDIT: I know why. EDIT: I think that's all I'm adding to the program at the moment. Here's the code:
|