Jump to content

Recommended Posts

Posted

Hello, in the following example, exclude.txt has 5 lines of text. The message box pops up 5 times to display each line of text. How can I make just one message box pop up with all 5 lines of text on one line?

Thanks|

$file = FileOpen("c:\temp\exclude.txt", 0)
If $file = -1 Then
   MsgBox(0, "Error", "Unable to open file.")
   Exit
EndIf

While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   MsgBox(0, "Test", $line)
WEnd
FileClose($file)
  • Moderators
Posted

You're example would only ever read the first line anyway. You never increase $line.

$sString = StringReplace(StringStripCR(FileRead("c:\temp\exclude.txt")), @LF, ' ')
MsgBox(64, 'Info', $sString)
The Carriage Returns/Line Feeds are replaced by spaces.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

Yes, I tried working with that but had the same problem - trying to get just one message box with all the text on just one line (no CRLF's).

  • Moderators
Posted

Yes, I tried working with that but had the same problem - trying to get just one message box with all the text on just one line (no CRLF's).

I gave you the answer then.

http://www.autoitscript.com/forum/index.ph...st&p=296180

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

You're example would only ever read the first line anyway. You never increase $line.

Not true.

If he hadn't used FileOpen but given FileReadLine the filename instead, it's true however.

When FileReadLine is given a handle it loops through the file, line by line.

$sFile = FileOpenDialog("", "", "Text (*.*)")
If @error Then Exit

$hFile = FileOpen($sFile, 0)
If @error Then Exit

While 1
    $sLine = FileReadLine($hFile)
    If @error Then ExitLoop
    
    MsgBox(64, "", StringLeft($sLine, 40) & "...")
WEnd

MsgBox(64, "", "Finished")
  • Moderators
Posted (edited)

Not true.

If he hadn't used FileOpen but given FileReadLine the filename instead, it's true however.

When FileReadLine is given a handle it loops through the file, line by line.

$sFile = FileOpenDialog("", "", "Text (*.*)")
If @error Then Exit

$hFile = FileOpen($sFile, 0)
If @error Then Exit

While 1
    $sLine = FileReadLine($hFile)
    If @error Then ExitLoop
    
    MsgBox(64, "", StringLeft($sLine, 40) & "...")
WEnd

MsgBox(64, "", "Finished")
I can honestly say, I didn't... I didn't even know that :) ... thanks. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...