Sign in to follow this  
Followers 0
bobheart

Random quotes

7 posts in this topic

Anyone can help me . I want to have a file that has some random quotes in it and can output one to a txt file I can use for my email sig .

How could I do it with a autoit file ?

I just don't get the random stuff .

Few below to show .

1.

It has always been the prerogative of children and half-wits to point out that the emperor has no clothes. But the half-wit remains a half-wit, and the emperor remains an emperor.

2.

Psychiatry enables us to correct our faults by confessing our parents' shortcomings.

3.

Nobody believes the official spokesman... but everybody trusts an unidentified source.

Share this post


Link to post
Share on other sites



You may make a file with a quote per line and using FileReadLine and Random() take a like and output in the .txt file you want.

Share this post


Link to post
Share on other sites

I was just playing with this when the email came about a comment here , it grabs the line but it keeps going till it is done reading every line ?

And I don't know how to output it to a txt file ?

$file = FileOpen("random.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Line read:", $line)
Wend

FileClose($file)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If you have a file called random.txt and you want to output one random line of that file to a new text file called out.txt, you can use the following code. Alter to your needs.

#include <File.au3>;allow us to use the CountLines function

Local $file, $out, $lines
$file = FileOpen("random.txt", 0)
$out = FileOpen("out.txt", 2)
If $file = -1 OR $out = -1 Then
  MsgBox(0, "Error", "Error reading one or both files.  Now exiting")
  Exit
EndIf
$lines = _FileCountLines("random.txt")
FileWrite($out, FileReadLine($file, Int(Random(1, $lines + 1))))

Edited to correct code

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Never seen this error ?

---------------------------

AutoIt Error

---------------------------

Line 11 (File "E:\Programs\AutoIt3\Examples\june28\random.au3"):

FileWrite($out, FileReadLine(Int(Random(1, $lines + 1))))

Error: File handle invalid. Make sure that the FileOpen command succeeded.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Forgot the file paramater on the FileReadLine call. This is what happends when I write code without testing it at 02:20 :D

Edit: Above code corrected.

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Thaat work , thank you , now I will study it .. :D

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  
Followers 0