Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading from file and assigning numbers
#1
Hello again Big Grin

I was able to get my program to write the information to a file the way that I want. I appreciate the help on my other post. Now I have a new problem. I want to write a number to the file, but I want the number to be determined by the number of records in the file. So, the first time that I run the program and enter information the number would be 1. Then if I keep adding information, the number would grow depending on the number of records that I add. So if I enter 5 records worth of information, I want the program to assign the number 6 to the 6th record. I need to print this on the screen for each record.

Here is the code that I have for the writing of the records to file.

Code:
WRITE.NEW:
OPEN "A:\LOG.DAT" FOR BINARY AS #1
    LG.PNO = LG.PNO + 1
    PUT #1, LOF(1) + 1, LG
CLOSE #1
PRINT
PRINT
PRINT "YOUR NEW PART NUMBER IS : "; LG.PROIDN$; LG.PNO
PRINT
PRINT
PRINT "PRESS M TO RETURN TO MAIN MENU OR E TO EXIT"

Any and all help is appreciated.
Reply
#2
really understood your question, but let L be the length of a record (number of bytes). N will be the number of records in the file.

DIM L AS INTEGER, N AS INTEGER, I AS LONG

After your opening your file:

N = LOF(1) \ L
DIM RECORDNUMBER(1 TO N) AS LONG
FOR I = 1 TO N
'
' Read in a record.
'
RECORDNUMBER(I) = I
NEXT I
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
Glenn,

I am sorry but I don't understand that code. I hate to be like this, but can you please explain the code you guys give me. I need to better understand the whole theory of the code and why you need to do things certain ways. I will send you a message with the whole code that I have written, maybe you can write what I should do on that and explain what exactly it is doing.

I really appreciate it.
Thanks
Chris
Reply
#4
LOF(1) is the number of bytes in file #1.
L is bytes per record.
N is LOF(1)/L, number of records in the file.

After opening the file, you want to put to the newest position (LOF(1) + 1) the data and the calculated N.


To do it all at the same time, do this: (part.info must be part of a TYPE for this to work, I think.)

Code:
OPEN "A:\LOG.DAT" FOR BINARY AS #1
j% = 1
FOR i% = 1 TO n%
PUT #1, j%, part.info
j% = j% + record.length%
next i%
CLOSE #1

'Notice: Real programmers (as opposed to professors) use "NUM", not "no".
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
part.info is now declared SINGLE. Doesn't have to be declared a type structure.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)