Sign in to follow this  
Followers 0
face

output random words from text file

7 posts in this topic

i have a script that aims to output random words from a text file

i need some help to make it work

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Local $mypath = @ScriptDir, $lines = ""
Local $output1 = _FileListToArrayRec($mypath, "*.txt", 1, 1, 0, 2)
Func _Main()

    GUICreate("words", 300, 400, -1, -1)
    Sleep(300)
    $output1 = GUICtrlCreateInput("", 60, 10, 60, 20, BitOR($ES_CENTER, $ES_READONLY))
    GUICtrlCreateLabel("Shape", 5, 12)
    $die = GUICtrlCreateLabel("", 700, 120, 700, 20, $SS_SUNKEN)
    GUICtrlSetFont($output1, 8, 800, "", "Verdana")
    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
                $results1 = Random(1, 2, 1)
                GUICtrlSetData($output1)

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

At no point do you actually ever read the file?  Why not worry about the GUI after getting some functionality remotely close to what you are trying to accomplish.  I would break into 4 tasks.

1) FileRead the file

2) StringSplit on spaces (this returns an $array, i prefer the 1 based)

3) then you can set a variable for $random = random(1 , $array[0] , 1)

4) then use that number as the index of the array element to be returned.  $array[$random]

...and using $output1 for an INPUT, not to mention that variable already being used for the filelist; that is not good practice. 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

can you write an example script if possible

Share this post


Link to post
Share on other sites

Can YOU write an example script, based on the advices given?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This has already been answered.  You should do a forum search, prior to posting.

Although, my regexp route should include ' and - to get all avaiable words.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

how can i make this script not exit by itself?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

   $File = FileReadToArray("words.txt")
    Local $iRandomResult = 0
    Local $hGUI = GUICreate("Random Words", 265, 150, -1, -1)
    Local $iButton1 = GUICtrlCreateButton("D2", 5, 25, 50, 30)
    Local $iOutput = GUICtrlCreateLabel("", 185, 45, 70, 50, BitOR($BS_PUSHLIKE, $SS_CENTER))
    GUICtrlSetFont($iOutput, 24, 800, "", "Comic Sans MS")
    GUISetState(@SW_SHOW, $hGUI)

    ; Run the GUI until the dialog is closed
    Sleep(5000)
    $iRandomResult = $File[Random(0, UBound($File) - 1, 1)]
    GUICtrlSetData($iOutput, $iRandomResult, $File )

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