Jump to content
Sign in to follow this  
coolness

reading random txt file line into a message box.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?


Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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)

 


Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...