Qbasicnews.com
February 28, 2020, 05:15:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: displaying, editing & deleting info on dat files  (Read 1620 times)
heavenraiza
Member
*
Posts: 80



« on: December 15, 2003, 10:00:49 PM »

Given the coding below, how would i go about displaying the info from file #1. I set up the PRINT statements but its not displaying the info that corresponds w/the key.name$ info. Please help.

Code:
Lookup:

CLS

INPUT "Enter name to search for: ", search$

  IF search$ = "" THEN
    GOTO Main.Menu
  END IF

GOSUB Search.Records

  IF record.number% = 0 THEN
    PRINT "Record Not Found"
    SLEEP 13
    GOTO Lookup
  END IF

  PRINT
   PRINT "Name "; RTRIM$(key.name$); " Found In Record Number "; record.number%
  PRINT
  PRINT "Name: "; RTRIM$(name$)
  PRINT "Address: "; RTRIM$(street$)
  PRINT "City: "; RTRIM$(city$)
  PRINT "State: "; RTRIM$(state$)
  PRINT "Zip: "; RTRIM$(zip$)
  PRINT "Phone#: "; RTRIM$(phone$)
  PRINT "SS#: "; RTRIM$(ss$)
 
  SLEEP 5
  GOTO Lookup

Search.Records:

GOSUB Emp.Recs
upper.record% = recs + 1
lower.record% = 0
record.input$ = UCASE$(search$)
record.input.length% = LEN(record.input$)
middle.record% = CINT(upper.record% / 2)

  IF middle.record% = 0 THEN
    record.number% = 0
    RETURN
  END IF

Redo:

GET #1
GET #2, middle.record%

  IF record.input$ = LEFT$(key.name$, record.input.length%) THEN
    record.number% = VAL(point.name$)
    RETURN
  END IF

  IF (middle.record% = upper.record% OR middle.record% = lower.record%) THEN
    record.number% = 0
    RETURN
  END IF

  IF record.input$ > LEFT$(key.name$, record.input.length%) THEN
    lower.record% = middle.record%
    middle.record% = middle.record% + CINT((upper.record% - lower.record%) / 2)
    GOTO Redo
  END IF

  upper.record% = middle.record%
  middle.record% = middle.record% - CINT((upper.record% - lower.record%) / 2)
  GOTO Redo

RETURN Main.Menu


Code:
' Open files and define the fields (columns) used for each file (table)

Open.Files:

  OPEN "R", #1, "c:/qb4.5/data/employee.dat", 256
  FIELD 1, 40 AS name$, 40 AS street$, 10 AS zip$, 30 AS city$
  FIELD 1, 120 AS bypass0$, 2 AS state$, 12 AS phone$, 11 AS ss$, 111 AS nul1$
  RSET nul1$ = "EOR"

  OPEN "R", #2, "c:/qb4.5/data/name.dat", 64
  FIELD 2, 40 AS key.name$, 7 AS point.name$, 17 AS nul2$
  RSET nul2$ = "EOR"

  OPEN "R", #3, "c:/qb4.5/data/ss.dat", 32
  FIELD 3, 11 AS key.ss$, 7 AS point.ss$, 14 AS nul3$
  RSET nul3$ = "EOR"

  OPEN "R", #4, "c:/qb4.5/data/zip.dat", 64
  FIELD 4, 5 AS look.zip$, 30 AS look.city$, 2 AS look.state$, 27 AS nul4$
  RSET nul4$ = "EOR"

RETURN


Code:
Build.Key.Files:

  GOSUB Emp.Recs

  FOR emp.count = 1 TO recs

    GET #1, emp.count
    LSET key.name$ = name$
    LSET point.name$ = STR$(emp.count)
    PUT #2, emp.count
    LSET key.ss$ = ss$
    LSET point.ss$ = STR$(emp.count)
    PUT #3, emp.count

  NEXT emp.count

RETURN


*Also, how would I go about editing & deleting info in these files? Thanx
Logged

here are 10 types of people, those that understand binary & those that dont. . .
Mango
Wandering Guru
***
Posts: 360



« Reply #1 on: December 16, 2003, 08:32:48 AM »

Hi there.  Have you read through the thread entitled, "Hey Agamemnus"?

Your code is ideally situated for a custom data-type, and modern subs rather than gosubs.
Logged
heavenraiza
Member
*
Posts: 80



« Reply #2 on: December 16, 2003, 08:57:55 PM »

i'll read, thanx.
Logged

here are 10 types of people, those that understand binary & those that dont. . .
Mango
Wandering Guru
***
Posts: 360



« Reply #3 on: December 16, 2003, 11:49:56 PM »

Quote from: "heavenraiza"
i'll read, thanx.


Just FYI...when I said custom data types, I meant, eg
Code:
TYPE People
   lname AS STRING * 10
   fname AS STRING * 10
   id AS INTEGER
END TYPE


and then you can create variables or arrays of variables that contain the whole record.   eg:

Code:
DIM bob AS People
bob.fname = "Bob"
bob.lname = "Smith"
bob.ID = some_variable


or...you can create a whole array of 'em...
DIM MyFriends(1000) as People
.
.
.
MyFriend(817).fname = name(17)
MyFriend(817).lname = "Burkewitiz"
.
.
.
name(219) = MyFriend(817).lname
.
.
.
.
'open file for output.....somewhere in here

x=0
do
  put #1 MyFriend(x)
  x=x+1
loop until x > last_record
.....

and I meant you can use at the beginning:
DECLARE SUB subname(parameter list)

...
in the program body

CALL subname(parameter list)

....

in a separate part of the program

defint a-z
SUB subname (parameter list)  ' A sub program

sub body code

END SUB
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!