03-30-2005, 04:38 AM
hi. my random access program is giving me a bad record length error at Put #3, x, all$. and i have no idea what im doing wrong.
code below
the objective of this program is to take some info from a sequencial file. put them into a random access file. make all name, age, city have the same length and put them all into one string. print name, age, city out by using the mid statement.
code below
the objective of this program is to take some info from a sequencial file. put them into a random access file. make all name, age, city have the same length and put them all into one string. print name, age, city out by using the mid statement.
Code:
REM Variable Dictionary
REM file$.....file address that contains the data
REM out$......the random access file output
REM port#.....ports for both input and output
REM count.....counts how many sets of data there are
REM namelen...longest name length
REM agelen....longest age length
REM citylen...longest city length
REM totlen....total length of the whole string
REM all.......the string containing name, city and age
REM nameadd...number of blanks to be added
REM ageadd....ditto
REM cityadd...ditto
CLS
CONST file$ = "f:\qb\people.txt"
CONST out$ = "f:\qb\out.dat"
CONST port = 1
CONST port2 = 2
OPEN file$ FOR INPUT AS #port
count = 0
WHILE NOT EOF(port)
INPUT #port, name$, age$, city$
count = count + 1
IF LEN(name$) > namelen THEN namelen = LEN(name$)
IF LEN(city$) > citylen THEN citylen = LEN(city$)
WEND
CLOSE #port
agelen = 3
totlen = namelen + citylen + agelen
OPEN file$ FOR INPUT AS #port2
OPEN out$ FOR RANDOM AS #3 LEN = totlen
FOR x = 1 TO count
INPUT #port2, name$, age$, city$
nameadd = namelen - LEN(name$)
FOR y = 1 TO nameadd
name$ = name$ + " "
NEXT y
ageadd = agelen - LEN(age$)
FOR y = 1 TO ageadd
age$ = age$ + " "
NEXT y
cityadd = citylen - LEN(city$)
FOR y = 1 TO cityadd
city$ = city$ + " "
NEXT y
all$ = name$ + age$ + city$
PUT #3, x, all$
NEXT x
CLOSE #3
CLOSE #port2
OPEN out$ FOR RANDOM AS #3 LEN = totlen
FOR x = 1 TO count
GET #3, x, all$
PRINT MID$(all$, 1, namelen), ;
PRINT MID$(all$, namelen + 1, namelen + 1 + agelen), ;
PRINT MID$(all$, namelen + agelen + 1, namelen + agelen + citylen + 1), ;
NEXT x
CLOSE #3
END