Jump to content

Recommended Posts

Posted (edited)

Hello, I am new to the forums aswell as autoit itself. I have a question that if answered will make me very grateful to you. So in spite of me coming off as annoyin here i go....Can someone please tell me how I would go about making a script that.

1.selects a random line from txt file

2.typing out the selected line

Ive managed to get line for line and have it open a msgbox but I haven't managed to get the line to be random aswell as having it typed out and entered. :(

if answered thank you so much! If not well poo on you.

Edited by damyo
Posted (edited)

Well that was a basic one:

Global Const $File = 'File path & name' : the & char is a 'put together' char

$ID = FileOpen($File,0) ;open the file

$a = 0

While 1

$a = $a + 1

$line = FileReadLine($file)

If @error = -1 Then ExitLoop

If Random(1,100) = $a then

MsgBox(0, "Line read:", $line)

ConsoleWrite( "Line read:" & $line & @CRLF)

Endif

Wend

FileClose($ID)

EndIf

This is somewhat strange but there is hundred ways to do this - but as example okay, this is real random as this get recounted at every line he!!!...

kjactive :(

Edited by kjactive
Posted (edited)

Hello, I am new to the forums aswell as autoit itself. I have a question that if answered will make me very grateful to you. So in spite of me coming off as annoyin here i go....Can someone please tell me how I would go about making a script that.

1.selects a random line from txt file

2.typing out the selected line

Ive managed to get line for line and have it open a msgbox but I haven't managed to get the line to be random aswell as having it typed out and entered.  :(

if answered thank you so much! If not well poo on you.

<{POST_SNAPBACK}>

so you already have the code to open the file for read...

so , I'll skip that and offer this sparse set of hints as yet another way:

$N_lines = _FileCountLines( $sFilePath )

$N_Rand = Random(1,$N_lines,1 )

$S_Rand_Line_From_File = FileReadLine ( filehandle or "filename" ,$N_Rand)

Add you own error checking.....

The above is untested code - let me know if it was anywhere near right.

edit: typo

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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