Jump to content

  • Log In with Google      Sign In   
  • Create Account

Creating a Random access file Troubles


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Poigahn   Crossbones+   -  Reputation: 519

Like
0Likes
Like

Posted 11 December 2012 - 08:17 AM

Need help with the proper math for a random access file on the harddrive. I need to create a list of words that are 18 charactors long ( Single Words ) Instead of doing a sequential read/write file. I want to use random access so that when I add a word I can alphabetize it when adding to it. What would be the proper seekfile read write method.

SeekFile(filenum,((Fileposition * 18)-18))
Word$ = Readstring(filenum)
if (Myword < Word$ ) Then
SeekFile(Filenum,((FilePosition * 18) - 18))
writestring(filenum,MyWord)
MyWord = WordString
End If
FilePosition ++
Loop

Not using actual code just psuedo coding above

Your Brain contains the Best Program Ever Written : Manage Your Data Wisely !!


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9599

Like
0Likes
Like

Posted 11 December 2012 - 09:39 AM

Did you try implementing your pseudocode? Did it work? If not, then what errors or incorrect behavior did you observe?

#3 Nypyren   Crossbones+   -  Reputation: 4311

Like
0Likes
Like

Posted 11 December 2012 - 12:08 PM

I suspect the underlying problem is that when you write at a position in a random access file, you *overwrite* what is already there. In order to insert, you have to shift the entire remainder of the file forward as well.

#4 Poigahn   Crossbones+   -  Reputation: 519

Like
0Likes
Like

Posted 12 December 2012 - 08:33 AM

I am not certain if I am Overwriting, Under-Reading or what ? My fixed String$ length is 18 charactors. I know the first element starts at 0 - But is the anything additional that gets written to a file that I need to account for or will the above math work ?
I have coded the routine. Wrote 6 TextStrings to the diskdrive, but I can't properly read then.
Does Seekfile Only work with binary files ?
Will seekfile Also work on textfiles if each string is the samelength ? ( Adding spaces to shorter words to get to the length of 18 )

Your Brain contains the Best Program Ever Written : Manage Your Data Wisely !!


#5 SiCrane   Moderators   -  Reputation: 9599

Like
0Likes
Like

Posted 12 December 2012 - 09:25 AM

How can we know how SeekFile works when you haven't mentioned what programming language, operating system or I/O library you are using? Also "I can't properly read then" isn't an adequate error description. What exactly goes wrong when you read the file? Did you try opening your file in something like a hex editor to see if it was written properly? And since you now have actual code instead of pseudo-code it would probably help if you showed what you actually wrote. This includes both writing and reading.

#6 Poigahn   Crossbones+   -  Reputation: 519

Like
0Likes
Like

Posted 14 December 2012 - 05:25 AM

What went wrong was 2 things. I could write the first data string with a fixed length of 18 charactors. When I try writing the next string by using SeekFile to position the pointer it would either be to short or to long ? Not Certain. Subsequently when I would try to read then Third String out of 5 and compare it to an identical string to make certain I war reading what I was writing, I would no get a match. So I did not know if the math calculation to position the pointer was off and by how many elements.
I Have since solved it by opening the file as a sequential read, reading in each string, The identifying the string size to determine how it was written to the disk drive and then adjusting the math accordingly.

In the end , Problem Solved

Your Brain contains the Best Program Ever Written : Manage Your Data Wisely !!





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS