Receiving info from a file. 
Author Message
 Receiving info from a file.

hello everyone,
I've created the following file:

cls
open "c:\students.dat" for random as #1
field 1, 6 as code$, 30 as name$
for i=1 to 5
input "Give Code";a$
lset code$=a$
input "Give name";b$
lset name$=b$
put #1,i
next i
close #1
end

My problem is that I want to create a program that can handle the above
file.
To be more specific the program should ask for a code. If the code
exists in the
file then the program should display on the screen the code and its
corresponding
name.
Else should ask for other code.(Is there a better way to create the
file? with matrixes
for example.)
Thanks in advance.



Sat, 18 Nov 2000 03:00:00 GMT  
 Receiving info from a file.



Quote:
> hello everyone,
> I've created the following file:

> cls
> open "c:\students.dat" for random as #1
> field 1, 6 as code$, 30 as name$
> for i=1 to 5

First of all, if your Basic supportes user-defined Types, replace all your
field, lset, rset
business with something like this:

Type Student
  Code As Integer
  Name As String * 30
End Type

Dim Students(x number of students) As Student

Then just read and write the entire Type to the file.  Don't use a string
as your key unless you absolutely have to have alphanumeric characters
in it for some reason.  Seek times are much faster for numeric keys.

To be able to retrieve a desired student by code, you need an ISAM library.
ISAM stands for Indexed Sequential Access Method.  There are many good
ISAM libraries for Basic, such as Bullet and QSAM.  There is quite a
learning
curve to using them, though.  They basically give your Basic compiler the
same
capabilities as dBASE or FoxPro.

John M.



Sun, 19 Nov 2000 03:00:00 GMT  
 Receiving info from a file.

Remove MAPSON if replying via email

Quote:
> hello everyone,
> I've created the following file:

> cls

' set Boolean flags
True = -1
False = 0

' creat student record data type
Type StudentType
        Code as String * 6
        Name as String * 30
End Type
Dim StudentRecord as StudentType

' get file handle number and open file
StudentFile=FreeFile

' next two lines are continuous
Open "C:\STUDENTS.DAT" For Random as StudentFile Len =
Len(StudentRecord)

' determine number of records already in file
StudentsInFile = Lof(StudentFile)\Len(StudentRecord)

'ask for searchword
Line Input "Look for which Code ? > ", LookFor$

' set found-it flag to false
Found = False

' start work loop driven ny number of existing records
For Z=1 to StudentsInFile

        ' read next record
        Get StudentFile,Z,StudentRecord

        ' compare to searchword

        ' if found a match
        If StudentRecord.Code = LookFor$ Then

                ' set found-it flag to true
                Found = True

                ' display the data
                Print "Found the following match:-"
                Print "Code : "; StudentRecord.Code
                Print "   Name : "; StudentRecord.Name
        End If
Next

' user message depends on whether or not a match was found
If Not Found Then
        Print "Sorry - no match found"!
Else
        Print "That's all."
Endif

Rob Davis MSc MIAP
Anstey, Leicester UK. 0976 379489



Mon, 20 Nov 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Receive Date Info from FTP file

2. Receiving Table type info into VB, then to HTML

3. get a file, parse it for info, display info on webpage

4. Receiving notification on Send, Receive and Delete

5. socket.receive fails to receive

6. Reading File Header Info (Binary Files)

7. info : here is how to delete cookies or any file in the temporary internet files folder

8. Getting file info using a file list box and putting in an array

9. Reading File Header Info (Binary Files)

10. File Info???File Date???

11. Reading File Header Info (Binary Files)

12. including file info in file list box

 

 
Powered by phpBB® Forum Software