Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GET ing information from a plain text file

Status
Not open for further replies.

robherc

Programmer
Apr 20, 1999
921
US
&nbsp;&nbsp;&nbsp;&nbsp;I am wanting to read a plain text file 1 character @ a time and place it into a *large* 2 dimensional $string array.<br>
&nbsp;&nbsp;&nbsp;&nbsp;As one of my primary projects that calls for this is a message encryption app I am unable to post sourcecode here AND pre-formatting theINPUT/BINARY (whichever works easier) file is NOT in the question.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;Any help would be GREATLY appreciated! :)<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thanks;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Robherc
 
well I am not as good as I was when I was taking programming in school. But I think it would be eaiser to just read the data one line at a time from the file and then break it down with the left$ right$ and mid$ commands. if you can not get it to work that way then send me details as to what you want to do and I will work on it and send you the results back then you can modify them to your liking.
 
I have tried both methods....what I'm wanting to do is to take text from an ordinary file, such as if you were to save this post as a .txt file, and read it into a *large* aray as DIMed below:<br>
<br>
DIM shared chrarray(1 to 1024, 1 to 1024) as string<br>
<br>
this seems to be such a simple task, but something jsut isn't working....my output always ends up giving me the correct number of "returns" but *absolutely* nothing for the lines; not even spaces!<br>
<br>
Thanks for any help you can give me.<br>
<br>
<br>
-Robherc
 
Can you tell us how you are currently filling the array?<br>

 
ummmm can't quite remember the *exact* source, but I'm using a binary get of 1 character in a<br>
<br>
FOR zx=1 TO 1024<br>
<br>
loop with a check for EOF.<br>
this fills each character into it's separate position "horizontally" into my "square" 1024x1024 array; I then use a DO WHILE NOT EOF loop (containing the FOR loop) to continue to the next "row" after zx has reached 1024<br>
<br>
ex:<br>
<br>
zw%=1<br>
DO WHILE NOT EOF<br>
FOR zx%=1 TO 1024<br>
GET #1, chrarray(zw%,zx%)<br>
if chrarray(zw%,zx%)=chr$(026) then<br>
chrarray(zw%,zx%)=""<br>
EXIT FOR<br>
EXIT DO<br>
NEXT<br>
LOOP<br>
<br>
I *know* this isn't quite how I had it before, but it's about the same conept.<br>
<br>
<br>
-Robherc
 
<br>
DIM shared chrarray(1 to 1024, 1 to 1024) as string<br>
ff = FREEFILE<br>
FileName$ = "INFILE.TXT"<br>
OPEN FileName$ FOR BINARY AS #ff<br>
FileSize& = LOF(ff)<br>
FOR Loop1& = 1 to 1024 'read up to 1024 times<br>
InBuffer$ = STRING$(1024, 0) 'clear the file buffer<br>
GET #ff, , InBuffer$<br>
FOR Loop2 = 1 to 1024 'fill the array with chars<br>
ChArray(Loop1, Loop2) = MID$(InBuffer$, Loop2, 1)<br>
NEXT<br>
IF (Loop1& * 1024)=&gt; FileSize& THEN EXIT FOR<br>
NEXT<br>
CLOSE #ff<br>
<br>
This would be much faster than trying to read the disk one-byte-at-a-time. You can read an entire file in about the time required to read a single byte. And, of course, the maximum file size would be 1048576 bytes. Any unused array elements would contain a null string. It might be more efficient to dimension the array with:<br>
Asize = SQR(FileSize&) + 1<br>
REDIM ChArray (1 to Asize, 1 to Asize)<br>
<br>
Also, none of this will work unless you decrease the size of ChArray and use the ' $DYNAMIC metacommand. At 1024x1024 you will run out of memory before the program has a chance to do it's job.<br>
<br>
Hope some of this helped....<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top