Jump to content

Random Line copy to Clipboard


Recommended Posts

Hi everyone.. I'm new to autoit just wondering if you could help me guys with my program making...

I've been going around reviewing the autoit help file and can't seem to find answers..

i wanted to pick a line from an notepad file randomly

and copy it to the clipboard

and paste it to IE as URL (using the IECREATE I guess?)

-its like === pick a RAnDom LiNe from "List of URLS.TXT"

copy to clipboard...

open IE (i know the code)

paste to URL address bar

Im using a windows xp and autoit v3 everything works fine...

please help me so that i can understand autoit better

THANKS in Advance

Link to comment
Share on other sites

If each of the URLs are on a different line then you can read the file into an array with _FileReadToArray() and then do Random() between 1 and Ubound() (the last element in the array -1) then use FileOpen() and FileReadLine() to read the line number found by the random function and then use that value to open the website.

edit - after rethinking this - you do not have to open the file nor read the line as the value is already in the array from reading the file - just use that index found by the random function and then use that for your variable to be used to open the website

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

this has not been tested, but should get you the idea

#include <IE.au3>
#Include <File.au3>
$filename = 'List of URLS.TXT' ;path to file with filename
Dim $ArrayOfURLs = _FileReadToArray($filename)
$randomURL = Random(1, UBound($ArrayOfURLs) - 1, 1)
_IECreate($ArrayOfURLs[$randomURL])

edit updated code as i missed the index and the array name

edit 2 - update code with changes from below

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

_IECreate(ArrayOfURLs[$randomURL])

should be

_IECreate($ArrayOfURLs[$randomURL])

*edit*

I would also change

$randomURL = Random(1, UBound($ArrayOfURLs) - 1)

to

$randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)

to get a whole number and no dicimals (as the array will have no decimals)

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

you are right - of course...

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

You could also use ShellExecute to open the default browser with the URL.

_IECreate($ArrayOfURLs[$randomURL]) ; This
ShellExecute($ArrayOfURLs[$randomURL]) ; Becomes this

Unless you're planning on using the IE.au3 file for something else later, and not just opening a web site randomly, you wouldn't need the include.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

thanks man but i think i need the include because im gonna do an imgclick on the IE (ive tested the imgclick and was successful)

i cant get to work it is there something wrong with this script...? my URL.txt is located in my desktop...

#include <IE.au3>
#Include <File.au3>
$filename = "C:\Documents and Settings\DivM\Desktop\URLS.txt"
Dim $ArrayOfURLs = _FileReadToArray($filename)
$randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)
_IECreate($ArrayOfURLs[$randomURL]))
Edited by pedrokangkong
Link to comment
Share on other sites

You missed my edit.

Random will return any number between the min and max

For example

Min = 1, Max = 3

it could return 1.5, 2.7, 1.1, etc.

The array doesn't have any decimals it is simply 0, 1, 2, 3, 4 etc.

so we need to add the "1" flag to the Random command so it doesn't return a decimal result.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

try changing this line $randomURL = Random(1, UBound($ArrayOfURLs) - 1)

to this one $randomURL = Random(1, UBound($ArrayOfURLs) - 1, 1)

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

yup i've added the edits

#include <IE.au3>
#Include <File.au3>
$filename = "C:\Documents and Settings\DivM\Desktop\URLS.txt"
Dim $ArrayOfURLs = _FileReadToArray($filename)
$randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)
_IECreate($ArrayOfURLs[$randomURL])

i'm trying to run this first before i merge it to the main script...

is there something we missed..?

Link to comment
Share on other sites

#include <IE.au3>
#Include <File.au3>
#Include <Array.au3>
$filename = "C:\Documents and Settings\DivM\Desktop\URLS.txt"
Dim $ArrayOfURLs = _FileReadToArray($filename)
_ArrayDisplay($ArrayOfURLs)
$randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)
_IECreate($ArrayOfURLs[$randomURL])

what does the array display show you?

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Program Files\AutoIt3\Examples\Helpfile\FileReadLine2121.au3"

C:\Program Files\AutoIt3\Examples\Helpfile\FileReadLine2121.au3 (4) : ==> Incorrect number of parameters in function call.:

Dim $ArrayOfURLs = _FileReadToArray($filename)

Dim $ArrayOfURLs = ^ ERROR

>Exit code: 1 Time: 0.325

Thanks for the help... really appreciating it..

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Program Files\AutoIt3\Examples\Helpfile\FileReadLine2121.au3"

C:\Program Files\AutoIt3\Examples\Helpfile\FileReadLine2121.au3 (5) : ==> Incorrect number of parameters in function call.:

Dim $ArrayOfURLs = _FileReadToArray($filename)

Dim $ArrayOfURLs = ^ ERROR

i missed the include array but still same error..

Edited by pedrokangkong
Link to comment
Share on other sites

Oh right...

it should be

_FileReadToArray($filename,$ArrayOfURLs)

#include <IE.au3>
#Include <File.au3>
$filename = "C:\Documents and Settings\DivM\Desktop\URLS.txt"
Dim $ArrayOfURLs[1]
_FileReadToArray($filename,$ArrayOfURLs)
$randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)
_IECreate($ArrayOfURLs[$randomURL])
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
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
 Share

  • Recently Browsing   0 members

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