1. Re: how get "number" in disk text file read into integer variable?

Ok Irv,

If you're suggesting that I may not have needed to do the integer-to-byte &
back again translation, I suspect you're probably right.

The file itself no longer exists, because it was created BY my app, & the
way it writes/reads now has made it different than it was; backtracking to
what looks like the relevant version before I fixed it with the
integer-to-byte translation, & using that one to make a file to look at, the
lines of interest show little rectangles, & here's a copy of one line  from
the file:


I know, that's not very informative, nor was it to me either; then I finally
figured out how to make the data I was reading in print to the screen, & I
could see that my ORIGINAL data (which was font size)  showed printed on the
screen as "25" (without the quotes), but the read in data from the file
(which was that original data written out to the file) showed as "{25}"
(without the quotes but with the curly braces). So I presume I could have
used that much more easily & directly than integer-to-byte translation, but
it was easier for me to just use the code that was suggested than to think
any more about it, as simple as it might be.

What I was doing  was writing & reading in a simple loop, some text and some
integer numbers on different lines in the file, & even though I was writing
& reading in exactly the same way, apparently that was fundamentally
inappropriate.

Here's how my loop WROTE data, with a "puts":

  for n=1 to 4 do     -- now write font info
    line = AllData[i][n] -- 1- 4 is various font data
    line = line & '\n' -- add a linefeed, so we can read it after it's
written
    puts(Handle, line)          -- write the line to the file.
  end for

And here's approximately how I READ it, with a "gets":
line = gets(Handle)
--<snip> tested to see if "record separator marker" was on that line,
--          that's why it's not all in the for loop below
aData[1]= line  -- put first font data into sequence "aData"
  for n = 2 to 4 do -- put rest of font data in
     line = gets(Handle)
     if atom(line) = 0 then          -- if NOT blank line?,
                 line = line[1..length(line)-1]-- remove line feed
     end if
     aData[n]= line
  end for
--<snip> and then after other data is read, it's all combined,:
 AllData= append(AllData, aData)
-- & then above is repeated again for another "record" until file is
finished

My problem manifested itself when I tried to say:
 setFont(Window,"fontType", AllData[RecordNumber][3],Bold),
where "3" was the position in my AllData variable that holds FontSize.

I assume my underlying problem was that the puts & gets work fine for simple
text, but not so fine for integers, & though I did try to diddle with the
read in data to get it to work, nothing I tried worked until I changed just
the integer data to write as byte & read the same (still using puts & gets
for the other text data).

Maybe I'll go back & see if I can figure how to do it simpler, but for now
the integer-to-byte xlation is working ok, even if it is unnecessary.

Dan Moyer



>----- Original Message -----
>From: Dan B Moyer <DANMOYER at PRODIGY.NET>
>To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
>Sent: Monday, January 31, 2000 2:02 AM
>Subject: Re: how get "number" in disk text file read into integer variable?
>
>
>> A belated thanks to M.Kollenaar for code to write & read integers from a
>> disk file; turns out I did need it after all, for a different part of my
>> structured variable than what I was originally asking about.
>
>Dan:
>
>Could you share with us one line from the file you are reading? The reason
>I ask is that I have not found an instance where Euphoria couldn't
>read human-readable data from a file using the standard input commands.
>(integers and reals stored by VB, C and Pascal are another story)
>
>Regards,
>Irv

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu