SjaakTV Posted March 4, 2010 Share Posted March 4, 2010 Hi, After a awesome kickoff on this forum I have a new problem. I want to make a script that can add words in a text file (already got that) But the second thing is i want to use this wordlist to check out a text. So i have 2 .txt file one is named wordlist other is named story. I have a other script that can check out a .txt file for only one word. I can't get it fixed to check it with the wordlist. First i thought i will get a mass of msg box's so that could be the reason it crashed but it is not. I would also like one msg box for all words. So if it checks like 15 words in one story and it find 7 words i don't want to see 8 popups it didn't found it and 7 that it found it. One popup is enough. I didnot tryed that yet because i need some help with fixing this problem. Thnx, This is the check script that can read one word. $file = FileOpen("story.txt", 0) $read = FileRead($file) If @error = -1 Then MsgBox(0, "Error", "File not read") Exit Else If StringRegExp($read,"Bird") Then MsgBox(0, "YEH", "We got him") Else MsgBox(0, "Nope", "Nothing found here.") EndIf EndIf FileClose($file) This is the full script check out reader function. expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{ESC}", "Stop") Global $NewWord, $start Func Stop() Exit 0 EndFunc ;==>Stop MENU() Func MENU() GUICreate("Stop spam", 400, 288) GUISetBkColor(0xaaaaaa) GUICtrlCreateLabel((@MON & "/" & @MDAY & "/" & @YEAR), 325, 10) $NewWord = GUICtrlCreateInput("New word", 30, 50, 200, 20, 1, 1) $add = GUICtrlCreateButton("Add", 270, 47, 33) $start = GUICtrlCreateButton("Start", 100, 200, 75, 45) GUISetState(@SW_SHOW) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $add AddWord() Case $Start reader() EndSwitch WEnd GUIDelete() EndFunc ;==>MENU Func AddWord() $a = GUICtrlRead($NewWord) $file1 = FileOpen("wordlist.txt", 1) FileWriteLine($file1, $a) FileClose($file1) EndFunc ;==>AddWord Func reader() $file1 = FileOpen("wordlist.txt", 0) $file = FileOpen("story.txt", 0) $read = FileRead($file) $i = 1 If @error = -1 Then MsgBox(0, "Error", "File not read") Exit Else If StringRegExp($read, FileReadLine($file1), $i ) then MsgBox(0, "YEH", "We got him") Else MsgBox(0, "Nope", "Nothing found here.") EndIf EndIf FileClose($file) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2010 Moderators Share Posted March 4, 2010 SjaakTV,Time to learn about arrays! There is a good tutorial in the Wiki here.What you will need to do:- Get the list of words you want to chek into an array - use _FileReadToArray will do that for you automatically.- Read the text - you have that already.- Use a For...Next loop to check each word in the array against the text. If you find a word add it to a list of "found" words.- Display a MsgBox with the list of "found" words.Easy-peasy, no? Give it a try - you know where we are if you run into problems.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...
SjaakTV Posted March 5, 2010 Author Share Posted March 5, 2010 Ty got it working now. Used a other array but it work. Thnx for your time. 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