Jump to content

Recommended Posts

Posted

This is what I have got.

 

Why aint it working guys?

 

#include <File.au3>
#include <MsgBoxConstants.au3>
$sFile = "text.txt"
$lines = _FileCountLines($sFile)
$sFile = FileOpen($sFile)
$line = FileReadLine($sFile, Random(1, $lines, 1))
MsgBox(4096, "", $line)
FileClose($sFile)

 

I would also like to learn how to write text into a txt file, if you know how.

Posted

the msgbox gave an error message, so I replaced it with this. MsgBox(4096, "Windy:", ($line)) and it still isn't showing the line in the msgbox. can someone please help?

Posted

Works for me.  Maybe add some error checking?

#include <File.au3>
#include <MsgBoxConstants.au3>
$sFile = "text.txt"
$lines = _FileCountLines($sFile)
ConsoleWrite("$lines: " & $lines & @TAB & "@error: " & @error & @CRLF)
$sFile = FileOpen($sFile)
ConsoleWrite("$sFile: " & $sFile & @TAB & "@error: " & @error & @CRLF)
$line = FileReadLine($sFile, Random(1, $lines, 1))
ConsoleWrite("$line: " & $line & @TAB & "@error: " & @error & @CRLF)
MsgBox(4096, "", $line)
FileClose($sFile)

Are you sure your $sFile is called text.txt and is in the same directory as your .au3 script?

Posted

I am trying to use an input box, to write a line to a txt file. Can you help?

 

 #include <File.au3>

$text = inputbox("write to txt", " write something: ")
$sFile = "test.txt"
$sFile = FileOpen($sFile)
$line = Filewriteline($text)
FileClose($sFile)

 

 

Why isn't this working?

Posted
4 hours ago, coolness said:

Why isn't this working?

Because of this line

4 hours ago, coolness said:

$line = Filewriteline($text)

The FileWriteLine function should have two parameters, the file handle [$sFile], then the text [$text]

like this

$line = FileWriteLine($sFile, $text)

 

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...