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:

code:
var users, choice : int
users := 0
var ip_array : array 0 .. users of string

loop
    put "Enter a choice:"
    put "1 - Enter new user."
    put "2 - Print list of users."
    put "3 - Exit."
    get choice
    if choice = 1 then
        cls
        put "Enter the IP address:"
        get ip_array (users)
        users += 1
    elsif choice = 2 then
        cls
        put "There are ",users," many user(s) in the database."
        for i : 0 .. users
            put ip_array (i)
        end for
    elsif choice = 3 then
        exit
    end if
end loop


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
code:
var ip_array : array 0 .. users of string

with
code:
var ip_array :flexible array 0 .. users of string


code:
        get ip_array (users)
        users += 1

with
code:

        get ip_array (users)
        users += 1
        new ip_array,users

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
code:
for i : 0 .. (users - 1)


And I've added a bit more.

code:
setscreen ("nocursor")

var users, choice : int
users := 0
var ch : string (1)
var ip_array : flexible array 0 .. users of string
var name_array : flexible array 0 .. users of string

loop
    put "Enter a choice:"
    put "1 - Enter new user."
    put "2 - Print list of users."
    put "3 - Number of users in database."
    put "4 - Exit."
    get choice
    if choice = 1 then
        cls
        put "Enter the name:"
        get name_array (users)
        put "Enter the IP address:"
        get ip_array (users)
        users += 1
        new name_array, users
        new ip_array, users
    elsif choice = 2 then
        cls
        for i : 0 .. (users - 1)
            put name_array (i), " - ", ip_array (i)
        end for
        getch (ch)
        cls
    elsif choice = 3 then
        cls
        put "There are ", users, " many user(s) in the database."
        getch (ch)
        cls
    elsif choice = 4 then
        exit
    end if
end loop


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.




Turing:

var some_Array:array -2..2 of int

put lower (some_Array)
put upper (some_Array)

put "There are " , upper(some_Array) - lower (some_Array) + 1," elements in the array"


As for the linked list there should be a tutorial somewhere. It should be under a pointer lesson.
Wink

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.
code:
setscreen ("nocursor")

var users, choice, data : int
users := 0
var ch : string (1)
var ip_array : flexible array 1 .. users of string
var name_array : flexible array 1 .. users of string

loop
    put "Enter a choice:"
    put "1 - Enter new user."
    put "2 - Print list of users."
    put "3 - Number of users in database."
    put "4 - Save list to file."
    put "5 - Load list from file."
    put "6 - Exit."
    get choice
    cls
    if choice = 1 then
        users += 1
        new name_array, users
        new ip_array, users
        put "Enter the name:"
        get name_array (users)
        put "Enter the IP address:"
        get ip_array (users)
        cls
    elsif choice = 2 then
        cls
        for i : 1 .. (users)
            put name_array (i), " - ", ip_array (i)
        end for
        getch (ch)
        cls
    elsif choice = 3 then
        cls
        put "There are ", users, " many user(s) in the database."
        getch (ch)
        cls
    elsif choice = 4 then
        open : data, "Database.txt", put
        put : data, users
        for e : 1 .. (users)
            put : data, name_array (e), " ", ip_array (e)
        end for
        close : data
        cls
    elsif choice = 5 then
        open : data, "Database.txt", get
        get : data, users
        for u : 1 .. (users)
            get : data, name_array (u), ip_array (u)
        end for
        close : data
        cls
    elsif choice = 6 then
        exit
    end if
end loop

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.

code:
var users, choice, data : int
users := 0
var ch : string (1)
var search : string
var ip_array : flexible array 1 .. users of string
var name_array : flexible array 1 .. users of string

loop
    put "Enter a choice:"
    put "1 - Enter new user."
    put "2 - Print list of users."
    put "3 - Number of users in database."
    put "4 - Save list to file."
    put "5 - Load list from file."
    put "6 - Search for an existing user."
    put "7 - Exit."
    get choice
    cls
    if choice = 1 then
        users += 1
        new name_array, users
        new ip_array, users
        put "Enter the name:"
        get name_array (users)
        put "Enter the IP address:"
        get ip_array (users)
        cls
    elsif choice = 2 then
        cls
        for i : 1 .. users
            put name_array (i), " - ", ip_array (i)
        end for
        getch (ch)
        cls
    elsif choice = 3 then
        put "There are ", users, " many user(s) in the database."
        getch (ch)
        cls
    elsif choice = 4 then
        open : data, "Database.txt", put
        put : data, users
        for i : 1 .. users
            put : data, name_array (i), " ", ip_array (i)
        end for
        close : data
        cls
    elsif choice = 5 then
        open : data, "Database.txt", get
        get : data, users
        for i : 1 .. users
            new name_array, users
            new ip_array, users
            get : data, name_array (i), ip_array (i)
        end for
        close : data
        cls
    elsif choice = 6 then
        put "Enter a name or IP you wish to search for."
        get search
        cls
        for i : 1 .. users
            if search = name_array (i) or search = ip_array (i) then
                put "Match found."
                put "IP or name searched for: ", search
                put "Matching IP or name:"
                put name_array (i), " - ", ip_array (i)
            end if
        end for
        getch (ch)
        cls
    elsif choice = 7 then
        exit
    end if
end loop

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". Smile




also, should have ending code of


else choice not = 1-8... then
put "that was not a choice."





just tips Wink

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:
code:
put index ("fdaheyfdaf", "hey")

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:

code:
View.Set ("text:1012;661")

var purchases, choice, data, balance : int
var ch : string (1)
var search : string
purchases := 0
var amount_subtracted : flexible array 1 .. purchases of string
var place_of_purchase : flexible array 1 .. purchases of string
var date_of_purchase : flexible array 1 .. purchases of string

loop
    put "Enter a choice:"
    put "1 - Enter new purchase."
    put "2 - Print list purchases."
    put "4 - Save list to file."
    put "5 - Load list from file."
    put "6 - Search for an existing purchase."
    put "7 - Exit."
    get choice
    if choice = 1 then
        purchases += 1
        new place_of_purchase, purchases
        new amount_subtracted, purchases
        new date_of_purchase, purchases
        put "Enter the place of purchase:"
        get place_of_purchase (purchases)
        put "Enter the total cost of purchase:"
        get amount_subtracted (purchases)
        put "Enter the date:"
        get date_of_purchase (purchases)
    elsif choice = 2 then
        for a : 1 .. 121
            put "-" ..
        end for
        put "-"
        put "-             Place of Purchase             -              Cost              -             Date of Purchase              -"
        for a : 1 .. 121
            put "-" ..
        end for
        put "-"

        for i : 1 .. purchases
            put "-", place_of_purchase (i), " - ", amount_subtracted (i), " - ", date_of_purchase (i)
        end for
        getch (ch)
    elsif choice = 4 then
        open : data, "Budget.txt", put
        put : data, purchases
        for i : 1 .. purchases
            put : data, place_of_purchase (i), " ", amount_subtracted (i), " ", date_of_purchase (i)
        end for
        close : data
    elsif choice = 5 then
        open : data, "Budget.txt", get
        get : data, purchases
        for i : 1 .. purchases
            new place_of_purchase, purchases
            new amount_subtracted, purchases
            new date_of_purchase, purchases
            get : data, place_of_purchase (i), amount_subtracted (i), date_of_purchase (i)
        end for
        close : data
    elsif choice = 6 then
        put "Enter the place of purchase or cost or date of which you wish to search for."
        get search
        put "Searching for: ", search
        for i : 1 .. purchases
            if search = place_of_purchase (i) or search = amount_subtracted (i) or search = date_of_purchase (i) then
                put "Match(es) found."
                put place_of_purchase (i), " - ", amount_subtracted (i), " - ", date_of_purchase (i)
                elsif then
                put "No matches found."
            end if
        end for
        getch (ch)
    elsif choice = 7 then
        exit
    end if
end loop



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:

code:
var student_first_names : array 1 .. 10 of string
var student_last_names : array 1 .. 10 of string
var student_years : array 1 .. 10 of int
var student_grades : array 1 .. 10 of int


This woud be used:

code:
type student : record
    first_name : string
    last_name : string
    year : int
    grade : int
end record

var students : array 1 .. 10 of student


Could I use the same type of structure?

Author:  Insectoid [ Fri Jul 18, 2008 7:55 pm ]
Post subject:  RE:Database

code:

type something : record
      amount_subtracted : string
      place_of_purchase : string
      date_of_purchase : string
end record

var somethings : flexible array 1..purchases of something


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:
code:
put student_first_names(i)

You would use:
code:
put somethings(i).first_name

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:
code:
var students : array 1 .. 10 of
    record
        first_name : string
        last_name : string
        year : int
        grade : int
    end record

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. Smile

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. Wink

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:

Turing:
var window : int := Window.Open ("text:1012;661")

var purchases, data, search_count, length1, length2, length3 : int
var balance : real := 0
var ch : string (1)
var search, choice : string
purchases := 0
search_count := 0
var variable_arrays : flexible array 1 .. purchases of
    record
        place_of_purchase : string
        amount_subtracted : string
        date_of_purchase : string
    end record

open : data, "Budget.txt", get
if not eof (data) then
    get : data, purchases
    get : data, balance
    for i : 1 .. purchases
        new variable_arrays, purchases
        get : data, variable_arrays (i).place_of_purchase, variable_arrays (i).amount_subtracted, variable_arrays (i).date_of_purchase
    end for
end if
close : data

loop
    put "Enter a choice:"
    put "1 - Enter new purchase."
    put "2 - Print list purchases."
    put "3 - Save list to file."
    put "4 - Load list from file."
    put "5 - Search for an existing purchase."
    put "6 - View balance."
    put "7 - Exit."
    get choice
    if strrealok (choice) then
        if strreal (choice) = 1 then
            purchases += 1
            new variable_arrays, purchases
            put "Enter the place of purchase:"
            get variable_arrays (purchases).place_of_purchase
            put "Enter the total cost of purchase:"
            get variable_arrays (purchases).amount_subtracted
            put "Enter the date:"
            get variable_arrays (purchases).date_of_purchase
        elsif strreal (choice) = 2 then
            for a : 1 .. 121
                put "-" ..
            end for
            put "-"
            put "-             Place of Purchase             -              Cost              -             Date of Purchase              -"
            for a : 1 .. 121
                put "-" ..
            end for
            put "-"
            for i : 1 .. purchases
                length1 := 42 - (length (variable_arrays (i).place_of_purchase))
                length2 := 31 - (length (variable_arrays (i).amount_subtracted))
                length3 := 42 - (length (variable_arrays (i).date_of_purchase))
                put "- ", variable_arrays (i).place_of_purchase ..
                for a : 1 .. length1
                    put " " ..
                end for
                put "- ", variable_arrays (i).amount_subtracted ..
                for b : 1 .. length2
                    put " " ..
                end for
                put "- ", variable_arrays (i).date_of_purchase
            end for
            getch (ch)
        elsif strreal (choice) = 3 then
            open : data, "Budget.txt", put
            put : data, purchases
            put : data, balance
            for i : 1 .. purchases
                put : data, variable_arrays (i).place_of_purchase, " ", variable_arrays (i).amount_subtracted, " ", variable_arrays (i).date_of_purchase
            end for
            close : data
        elsif strreal (choice) = 4 then
            open : data, "Budget.txt", get
            get : data, purchases
            get : data, balance
            for i : 1 .. purchases
                new variable_arrays, purchases
                get : data, variable_arrays (i).place_of_purchase, variable_arrays (i).amount_subtracted, variable_arrays (i).date_of_purchase
            end for
            close : data
        elsif strreal (choice) = 5 then
            put "Enter what you would like to search for."
            get search
            put "Searching for: ", search
            for i : 1 .. purchases
                if index (Str.Lower (variable_arrays (i).place_of_purchase), Str.Lower (search)) > 0 then
                    search_count += 1
                elsif index (Str.Lower (variable_arrays (i).amount_subtracted), Str.Lower (search)) > 0 then
                    search_count += 1
                elsif index (Str.Lower (variable_arrays (i).date_of_purchase), Str.Lower (search)) > 0 then
                    search_count += 1
                end if
            end for
            if search_count >= 1 then
                put search_count, " match(es) found."
                for a : 1 .. 121
                    put "-" ..
                end for
                put "-"
                put "-             Place of Purchase             -              Cost              -             Date of Purchase              -"
                for a : 1 .. 121
                    put "-" ..
                end for
                put "-"
                for i : 1 .. purchases
                    if index (Str.Lower (variable_arrays (i).place_of_purchase), Str.Lower (search)) > 0 then
                        length1 := 42 - (length (variable_arrays (i).place_of_purchase))
                        length2 := 31 - (length (variable_arrays (i).amount_subtracted))
                        length3 := 42 - (length (variable_arrays (i).date_of_purchase))
                        put "- ", variable_arrays (i).place_of_purchase ..
                        for a : 1 .. length1
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).amount_subtracted ..
                        for b : 1 .. length2
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).date_of_purchase
                    elsif index (Str.Lower (variable_arrays (i).amount_subtracted), Str.Lower (search)) > 0 then
                        length1 := 42 - (length (variable_arrays (i).place_of_purchase))
                        length2 := 31 - (length (variable_arrays (i).amount_subtracted))
                        length3 := 42 - (length (variable_arrays (i).date_of_purchase))
                        put "- ", variable_arrays (i).place_of_purchase ..
                        for a : 1 .. length1
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).amount_subtracted ..
                        for b : 1 .. length2
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).date_of_purchase
                    elsif index (Str.Lower (variable_arrays (i).date_of_purchase), Str.Lower (search)) > 0 then
                        length1 := 42 - (length (variable_arrays (i).place_of_purchase))
                        length2 := 31 - (length (variable_arrays (i).amount_subtracted))
                        length3 := 42 - (length (variable_arrays (i).date_of_purchase))
                        put "- ", variable_arrays (i).place_of_purchase ..
                        for a : 1 .. length1
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).amount_subtracted ..
                        for b : 1 .. length2
                            put " " ..
                        end for
                        put "- ", variable_arrays (i).date_of_purchase
                    end if
                end for
            else
                put "No matches found."
            end if
            search_count := 0
            getch (ch)
        elsif strreal (choice) = 6 then
            for i : 1 .. purchases
                balance -= strreal (variable_arrays (i).amount_subtracted)
            end for
            put "The balance is: $", balance
            balance := 0
        elsif strreal (choice) = 7 then
            exit
        end if
    end if
end loop

Window.Close (window)


: