Jump to content
Sign in to follow this  
Merchants

Find and match

Recommended Posts

Merchants

at the green spot i need a find system

like this:

input = Backdraft

in Database file:

Database Films

Film Name: Backdraft || Audio: Englist || Sub: Dutch, Multi || DVD box: Singel || DVD's: 1

Film Name: True Legend || Sub: Dutch || DVD box: Singel || DVD's: 1

Film Name: Artificlal Intelligence || Audio: Englist || Sub: Dutch, Multi || DVD box: Singel || DVD's: 1

Film Name: Species 1,2,3,4 || Audio: Englist || Sub: Dutch, Multi || DVD box: Qaud || DVD's: 4

next it must find the input words

and if exist then give a msgbox

#include <GUIConstantsEx.au3>
#Include <File.au3>
#NoTrayIcon

Global $GUI[30], $Last_Folder = -1, $last_used = "Characters"
$GUI[0] = GUICreate("Film Database", 251, 178)
GUICtrlCreateLabel("Film name", 15, 20)
$GUI[1] = GuiCtrlCreateInput("", 15, 35, 220, 20)
GUICtrlCreateLabel("Audio", 15, 60)
GUICtrlCreateLabel("Sub", 80, 60)
GUICtrlCreateLabel("DVD box", 145, 60)
GUICtrlCreateLabel("DVD's", 210, 60)
$GUI[2] = GuiCtrlCreateCheckbox("Englist", 15, 75)
$GUI[3] = GuiCtrlCreateCheckbox("Dutch", 15, 95)
$GUI[4] = GuiCtrlCreateCheckbox("Multi", 15, 115)

$GUI[5] = GuiCtrlCreateCheckbox("Dutch", 80, 75)
$GUI[6] = GuiCtrlCreateCheckbox("Multi", 80, 95)

$GUI[7] = GuiCtrlCreateRadio("Singel", 145, 75)
$GUI[8] = GuiCtrlCreateRadio("Dubbel", 145, 95)
$GUI[9] = GuiCtrlCreateRadio("Qaud", 145, 115)
GUICtrlSetState($GUI[7], $GUI_CHECKED)

GuiCtrlCreateGroup("Add film to database",5,5,240,165)
$GUI[10] = GuiCtrlCreateRadio("1", 210, 75)
$GUI[11] = GuiCtrlCreateRadio("2", 210, 95)
$GUI[12] = GuiCtrlCreateRadio("3", 210, 115)
$GUI[13] = GuiCtrlCreateRadio("4", 210, 135)
GUICtrlSetState($GUI[10], $GUI_CHECKED)

$GUI[14] = GUICtrlCreateButton("Add Film", 14, 140, 90, 22)
$GUI[15] = GUICtrlCreateButton("Close", 110, 140, 90, 22)

GUISetState(@SW_SHOW, $GUI[0])

While 1
    $GUI[16] = GUIGetMsg($GUI[0])
    Select
        Case $GUI[16] = $GUI_EVENT_CLOSE
            Exit
        Case $GUI[16] = $GUI[15]
            Exit
        Case $GUI[16] = $GUI[14]
            If Not FileExists(@ScriptDir & "\Database") Then DirCreate(@ScriptDir & "\Database")
            If Not FileExists(@ScriptDir & "\Database\Database.txt") Then
                _FileCreate(@ScriptDir & "\Database\Database.txt")
                $file = FileOpen(@ScriptDir & "\Database\Database.txt", 1)
                FileWrite($file, "Database Films" & @CRLF & "" & @CRLF & "" & @CRLF & "")
                FileClose($file)
            EndIf
            $file = FileOpen(@ScriptDir & "\Database\Database.txt", 0)
            For $CountLines = _FileCountLines(@ScriptDir & "\Database\Database.txt") To 0 Step -1
                $line = FileReadLine($file)
                If @error = -1 Then ExitLoop
                ; need a match system
            Next
            FileClose($file)
            $file = FileOpen(@ScriptDir & "\Database\Database.txt", 1)
            $Text = "Film Name: " & GUICtrlRead($GUI[1])
            If GUICtrlRead($GUI[2]) = $GUI_CHECKED Then
                If GUICtrlRead($GUI[3]) = $GUI_CHECKED Then
                    If GUICtrlRead($GUI[4]) = $GUI_CHECKED Then
                        $Text &= " || Audio: Englist, Dutch, Multi"
                    Else
                        $Text &= " || Audio: Englist, Dutch"
                    EndIf
                Else
                    $Text &= " || Audio: Englist"
                EndIf
            ElseIf GUICtrlRead($GUI[3]) = $GUI_CHECKED Then
                If GUICtrlRead($GUI[4]) = $GUI_CHECKED Then
                    $Text &= " || Audio: Dutch, Multi"
                Else
                    $Text &= " || Audio: Dutch"
                EndIf
            ElseIf GUICtrlRead($GUI[4]) = $GUI_CHECKED Then
                $Text &= " || Audio: Multi"
            EndIf
            If GUICtrlRead($GUI[5]) = $GUI_CHECKED Then
                If GUICtrlRead($GUI[6]) = $GUI_CHECKED Then
                    $Text &= " || Sub: Dutch, Multi"
                Else
                    $Text &= " || Sub: Dutch"
                EndIf
            ElseIf GUICtrlRead($GUI[6]) = $GUI_CHECKED Then
                $Text &= " || Sub: Multi"
            EndIf
            If GUICtrlRead($GUI[7]) = $GUI_CHECKED Then
                $Text &= " || DVD box: Singel"
            ElseIf GUICtrlRead($GUI[8]) = $GUI_CHECKED Then
                $Text &= " || DVD box: Dubbel"
            Else
                $Text &= " || DVD box: Qaud"
            EndIf
            If GUICtrlRead($GUI[10]) = $GUI_CHECKED Then
                $Text &= " || DVD's: 1"
            ElseIf GUICtrlRead($GUI[11]) = $GUI_CHECKED Then
                $Text &= " || DVD's: 2"
            ElseIf GUICtrlRead($GUI[12]) = $GUI_CHECKED Then
                $Text &= " || DVD's: 3"
            Else
                $Text &= " || DVD's: 4"
            EndIf
            MsgBox(64,"",$Text)
            FileWrite($file, @CRLF & $Text)
            FileClose($file)
    EndSelect
WEnd
Edited by Merchants

Share this post


Link to post
Share on other sites
Merchants

i found a kind of way but this does not work 100%

$file = FileOpen(@ScriptDir & "\Database\Database.txt", 0)
For $i = 0 To _FileCountLines(@ScriptDir & "\Database\Database.txt") Step +1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringRegExp(GUICtrlRead($GUI[17]), $line) Then
        If Not GUICtrlRead($GUI[17]) = "" Then
            MsgBox(48,"Film Database","This film exists! at line: " & $i + 1 & $line)
            ExitLoop
        EndIf
    EndIf
Next
FileClose($file)

Share this post


Link to post
Share on other sites
MvGulik

You do know it pays to be a little bit more specific in what its doing wrong in your view.

Only thing that catches my eye is that comparing against a empty string is best done with a [==] instead of a [=].

... Not 100% -> 99% still very good .. 0% not so good. ...

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Lococobra

Well there is one very obvious problem. You're using user input as a regular expression.

There are many characters that have special meaning in regular expressions, so this is not going to work. You could run the user input through a number of filters to escape any characters that have special meaning. Also, you should probably include a case insensitivity flag in there "(?i)".

To get you started.. here are the characters that you need to escape: (I think this is all of them but I'm not 100% sure)

()[]{}.+*?\|

Share this post


Link to post
Share on other sites
Merchants

make it simpel

just like you do in a text file Ctrl+F

and you enter the film name and press find

Edited by Merchants

Share this post


Link to post
Share on other sites
MvGulik

Problem solved ?

+ If you do a simple string search. Why the StringRegExp() use and not just StringInString() ?

---

Mmm, don't think it probably makes much different in this case, but if the input comes from your Gui. It makes more sense to put in in the pattern sloth instead of the text sloth.

StringRegExp ( "test"               , "pattern" [, flag ] [, offset ] ] )
StringRegExp ( GUICtrlRead($GUI[17]), $line)
---

On second though I think that is probably your problem. (swapped parameters)

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Merchants

wel problem is solved thx to iEvKI3gv9Wrkd41u

$file = FileOpen(@ScriptDir & "\Database\Database.txt", 0)
$count = 0
$Temp_text = ""
For $i = 0 To _FileCountLines(@ScriptDir & "\Database\Database.txt") Step +1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, GUICtrlRead($GUI[17])) Then
        If Not GUICtrlRead($GUI[17]) = "" Then
            $count += 1
            $Temp_text &= $line & @CRLF & @CRLF
        EndIf
    EndIf
Next
If $count Then
    MsgBox(64,"Film Database","Number of film results: " & $count & @CRLF & @CRLF & $Temp_text)
Else
    MsgBox(64,"Film Database","Film was not found!")
EndIf
FileClose($file)
Edited by Merchants

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.