way1000 Posted August 1, 2016 Share Posted August 1, 2016 i have a script with an array. it has to read the array values from a text file instead of from within the script. the text file has 58k lines of words from which i need to have as a result only 1 word at a time. so now it has to read from the text file only 1 line at a time and write it as a result to another text file expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <Date.au3> Global $result1s[3]=["text1", "text2", "text3"] _Main() Func _Main() Local $button1 Local $output, $die, $msg, $results1 Local $file = FileOpen("test.txt", 1) Local $g_idEdit GUICreate("test", 600, 200, -1, -1) $button1 = GUICtrlCreateButton("Result", 460, 110, 50, 30) $output1 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) $g_idEdit = GUICtrlCreateEdit("", 60, 10, 450, 20, $SS_LEFT) $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 2, 1) GUICtrlSetData($output1, $result1s[$results1]) $read1 = GUICtrlRead($output1) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit)) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 1, 2016 Moderators Share Posted August 1, 2016 way1000, If you want to read a file one line at a time, take a look at FileReadLine. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SadBunny Posted August 1, 2016 Share Posted August 1, 2016 Also, could you maybe give an example of, like, three lines of input, and the required three lines of output? There may be much better ways to code this kind of thing. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Skysnake Posted August 1, 2016 Share Posted August 1, 2016 I am intrigued. 58k lines, which you want to parse one word at a time. Pray tell why? If this is ten words per line, you are looking at ~580 000 words. Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
SadBunny Posted August 1, 2016 Share Posted August 1, 2016 Indeed. It smells like the kind of thing one might be much better off doing through powershell or maybe some Cygwin-based linux magic Although of course AutoIt is fine as well. Skysnake 1 Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
kylomas Posted August 2, 2016 Share Posted August 2, 2016 (edited) way1000, A couple of examples of reading a file to an array using regex. #include <array.au3> local $sFile1 = @scriptdir & '\file1.txt' local $sFile2 = @scriptdir & '\file2.txt' ; one word per line local $aResult = stringregexp(fileread($sFile1),'.*\R',3) _arraydisplay($aResult,'One Word per line') ; multiple words per line, varying delimiters (@CRLF, @TAB, space and comma) local $aResult = stringregexp(fileread($sFile2),'(?m)(\b[^\s,]+\b)',3) _arraydisplay($aResult,'Multiple Words per line') In the future it will serve you well to provide examples of your input, your code (or a reproducer) and what you expect as a result. Good Luck, kylomas edit - files used for testing...file1.txt file2.txt In the interest of completeness a non sre version... #include <array.au3> #include <StringConstants.au3> local $sFile1 = @scriptdir & '\file1.txt' local $aResult = stringsplit(fileread($sFile1),@CRLF,$STR_ENTIRESPLIT) _arraydisplay($aResult,'One Word per line') Edited August 2, 2016 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
AutoBert Posted August 2, 2016 Share Posted August 2, 2016 (edited) and here a non sre version for file2.txt: #include <Array.au3> local $sFile1 = @scriptdir & '\file2.txt' Local $aResult=StringSplit(StringStripWS(StringReplace(StringReplace(StringReplace(FileRead('file2.txt'),@CRLF,' '),@TAB,' '),',',' '),7),' ',3) _ArrayDisplay($aResult) Edited August 2, 2016 by AutoBert Link to comment Share on other sites More sharing options...
SadBunny Posted August 2, 2016 Share Posted August 2, 2016 27 minutes ago, AutoBert said: and here a sre version for file2: Where?! Wheeeeeerrrre?! Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
AutoBert Posted August 2, 2016 Share Posted August 2, 2016 ups, forgotten the word: non Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now