Jump to content
Sign in to follow this  
SjaakTV

Check .txt for words.

Recommended Posts

SjaakTV

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.

#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

Share this post


Link to post
Share on other sites
Melba23

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? :mellow: 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
SjaakTV

Ty got it working now.

Used a other array but it work.

Thnx for your time.

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  

×