Jump to content

Random $line read and copy


Recommended Posts

Hi, so i am in need of  this func to be able to finish my project, i have found this jewel in old posts from 2011.

The problem is that is not running the script

 

HotKeySet("q", "read")
Func read()
$filename = "configs.txt"
Dim $ArrayOfURLs[1]
_FileReadToArray($filename,$ArrayOfURLs)
Local $randomURL = Random(1, UBound($ArrayOfURLs) - 1,1)
_IECreate($ArrayOfURLs[$randomURL])
MsgBox($MB_SYSTEMMODAL, $randomURL, 10)
Endfunc

What should this do? Should read a random line from "configs.txt", if someone can help me with this, i would appreciate it a lot.

#inluded: IE.au3,file.au3,msgboxconstants.au3

Link to comment
Share on other sites

  • Moderators

@Alpha1 you should never just take code, especially if you don't understand  what it is doing. How about explaining exactly what you need to do. You want to read random lines from a text file, great - to what end? where is the file located? are you simply reading in the line or are you looking for specific text in that line? Help us help you

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

You have nothing in the script to keep it running. It starts and immediately ends, unless there's more to it than what's posted. If this isn't the whole script, post the script you're using.

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

 

Just now, JLogan3o13 said:

@Alpha1 you should never just take code, especially if you don't understand  what it is doing. How about explaining exactly what you need to do. You want to read random lines from a text file, great - to what end? where is the file located? are you simply reading in the line or are you looking for specific text in that line? Help us help you

3

@JLogan3o13, thank you for your answer!

Ok, sure thing, so the program must read one line from configs.txt(random) which is placed in the same folder as the script. After reading it has to send the line which was just read, key by key. What will the program read from those lines? 

100

101

102

.

.

.

297

 

Link to comment
Share on other sites

5 minutes ago, BrewManNH said:

You have nothing in the script to keep it running. It starts and immediately ends, unless there's more to it than what's posted. If this isn't the whole script, post the script you're using.

I am interested in making this function work, then i can use it in the main script

Link to comment
Share on other sites

  • Moderators

You're not providing a ton of information. This snippet will read random lines from a text file 20 times and output to the console, you should be able to modify to your needs:

$sFile = @ScriptDir & "\Test.txt"

For $a = 1 to 20
    ConsoleWrite(FileReadLine($sFile, Random(1,9)) & @CRLF)
Next

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

16 minutes ago, JLogan3o13 said:

You're not providing a ton of information. This snippet will read random lines from a text file 20 times and output to the console, you should be able to modify to your needs:

$sFile = @ScriptDir & "\Test.txt"

For $a = 1 to 20
    ConsoleWrite(FileReadLine($sFile, Random(1,9)) & @CRLF)
Next

 

@JLogan3o13 Thank you very much!

Can you help me with sending the result key by key too? 

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