Class Notes:

 

Importance of the search program.
Let’s change the name of computer

How about we call it LOOKER?
Why was the computer designed?

It was designed primarily compute mathematic equations.

Is the computer computing today?

No, it is searching. Everything is about searching, sending e-mails.
Tomorrow we’ll do some array.

Remarks from last class:

VISUAL BASIC CODE:
Code should be in a button click
     Dim id, searchid, i As Integer

        Dim price As Double

Dim fin As IO.StreamReader = IO.File.OpenText("supermarket.txt")

        i = 1

        searchid = TextBox1.Text

       

        While (fin.Peek <> -1)

             id = fin.ReadLine

            price = fin.ReadLine

             If id = searchid Then

                TextBox2.Text = FormatCurrency(price)

                Exit While

            End If

            i = i + 1

        End While

        If fin.Peek = -1 Then

            TextBox2.Text = "ITEM NOT FOUND "

        End If

Note taken from: http://samples.gotdotnet.com/quickstart/howto/doc/logfile.aspx

At this point, you have finished updating your log file. Normally, you would shut the file so anyone can open it and see the log entries. To read the file, you have to make a StreamReader. Again, the FileStream does have a Read method, although creating a StreamReader makes this easier. Having made the StreamReader , you need to point it to some place in your file, although this time you are going to move to the beginning of the file and move from there.

In order to determine when you have reached the end of the file, you have to 'peek' at the file from the current position of the StreamReader current position. If you have reached the end of the file (signified by a value less than zero), it does not keep reading the file since there is no information left. However, if there is still some information to read, you can instruct your reader to get the next line of information, using its ReadLine method. Once finished, you can close the Stream, the Reader, and the Writer .

 
            StreamReader r = new StreamReader(fs); // create a stream reader 
            r.BaseStream.Seek(0, SeekOrigin.Begin); // set the file pointer to the 
            beginning While (r.Peek() > -1) { // while not at the end of the file 
            output.Append(r.ReadLine()); // get the next line of information from the file 
            output.Append("\n"); // a newline } w.Close(); // close the writer and 
            underlying file r.Close(); // close the read
        
 
            Dim r As StreamReader = New StreamReader(fs) ' create a Char reader 
            r.BaseStream.Seek(0, SeekOrigin.Begin) ' set the file pointer to the beginning 
            While r.Peek() > -1 ' while not at the end of the file 
            output.Append(r.ReadLine()) ' get the next line of information from the file 
            output.Append( chr(13) ) ' a newline End While w.Close() ' close the writer and 
            underlying file r.Close() ' close the read