Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Line skip in WriteLn

Hi, is it possible to skip a line and then write in the Writeln command.

i need to check to see if any of 6 booleans are true then write to the corresponding line. i.e

------------------------------------------------------------------
if Selected[3] = true then
write to line 3
------------------------------------------------------------------

i tried all yesturday but it just kept writing all six lines.



regards

dcg.


Comments

  • zibadianzibadian Member Posts: 6,349
    : Hi, is it possible to skip a line and then write in the Writeln command.
    :
    : i need to check to see if any of 6 booleans are true then write to the corresponding line. i.e
    :
    : ------------------------------------------------------------------
    : if Selected[3] = true then
    : write to line 3
    : ------------------------------------------------------------------
    :
    : i tried all yesturday but it just kept writing all six lines.
    :
    :
    :
    : regards
    :
    : dcg.
    :
    :
    :
    You can call Writeln without any parameters, which will skip a line. An if-then-else is what you need for something like this to work. Here is a code based on your code snibbit:
    [code]
    for i := 1 to 6 do
    if Selected[i] then
    Writeln(i)
    else
    Writeln;
    [/code]
    Note: if you compare a boolean variable, you don't need to add '= true', because the if-then statement requires an boolean between the "if" and the "then" and there is one there already.
    If only the Selected[3] is true then the output will look like this:
    [code]


    3



    [/code]
    There are other ways to tackle this problem, but this is the easiest.
  • david gricedavid grice Member Posts: 2
    cheers,

    yes i have alot of file that look like that. I need it to leave the other lines well alone, i have sorted it now, not sure how am getting rid of the hacked code now.


    thanks

    dcg

  • zibadianzibadian Member Posts: 6,349
    : cheers,
    :
    : yes i have alot of file that look like that. I need it to leave the other lines well alone, i have sorted it now, not sure how am getting rid of the hacked code now.
    :
    :
    : thanks
    :
    : dcg
    :
    :
    Another solution is to use the TStringList object. It has build-in text file I/O routines and allows you to access the lines as if it's an array.
Sign In or Register to comment.