Jump to content

[RESOLVED] File to Array and then find all searches


Recommended Posts

Ok, so i'm still new, but having fun nonetheless, using the help file as much as i can, but I still can't figure this out.

I want to read the contents of a file into an array, and then search that array, and then return all results. Right now, of course, the results are just going to a MSGBOX, but once searched properly, I want to be able to add them to a list view, so that when a user clicks a result, it can load up the relevant webpage for them.

How in the world do i modify my script below to show ALL results? Note my feeble attempt at doing it lol

#include <INet.au3>
#include <GUIConstants.au3>
#include <IE.au3>
#include <Array.au3>
#include <file.au3>
GUICreate("Hello World", 900, 900)

$listview = GUICtrlCreateListView ("",10,10,200,150);,$LVS_SORTDESCENDING)
$data = ""

GUISetState(@SW_SHOW)

Dim $aRecords
If Not _FileReadToArray("btc\db.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

$Input = InputBox("ArraySearch Demo", "String To Find?")
If @error Then Exit

    $Pos = _ArraySearch ($aRecords, $Input, 0, 0, 0, True)
    MsgBox(0, "test: Positio: " & $pos, $aRecords[$pos])
while 1
    $Pos = _ArraySearch ($aRecords, $Input, 0, 0, 0, True)
    MsgBox(0, "test: Positio: " & $pos, $aRecords[$pos])
WEnd
Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Note, i did find the tol that was posted: http://www.autoitscript.com/forum/index.php?showtopic=51629

However, that doesn't seem to work either. I know for a fact that my term, HOME for example appears in the list 16 times, but the script only returns 1. So, it's not returning them all.

#include <INet.au3>
#include <GUIConstants.au3>
#include <IE.au3>
#include <Array.au3>

#include <file.au3>
GUICreate("Hello World", 900, 900)

$listview = GUICtrlCreateListView ("",10,10,200,150);,$LVS_SORTDESCENDING)
$data = ""

GUISetState(@SW_SHOW)

Dim $aRecords
If Not _FileReadToArray("btc\db.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

Func _ArrayFindAll($iArray, $iQuery, $iStart = 0,  $iEnd = 0, $iCaseSense = 0, $fPartialSearch = True)
    Local $Rtn = ''

    While 1
        $aSrch = _ArraySearch($iArray, $iQuery, $iStart,  $iEnd, $iCaseSense, $fPartialSearch)
        If $aSrch <> -1 Then
            $Rtn &= $aSrch & '|'
            $iStart = $aSrch + 1
            If $iStart >= $iEnd Then ExitLoop
        Else
            ExitLoop
        EndIf
    Wend

    If $Rtn <> '' Then
        $Rtn = StringSplit(StringTrimRight($Rtn, 1), '|')
        Return $Rtn
    Else
        Return SetError(1, 1, 'No matches to your query were found')
    EndIf
EndFunc 
$fQuery = ""

If IsArray($aRecords) Then
        $Found = _ArrayFindAll($aRecords, "HOME")
        If IsArray($Found) Then
            MsgBox(0, 'Elements', "It's an array with " & $Found[0] & ' elements')

            For $I = 1 To $Found[0]
                MsgBox(0, 'Values', $aRecords[$Found[$I]], 3)
            Next

        Else
            MsgBox(0,'No Matches', $Found)
        EndIf
        EndIf

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Well,

I see that if i remove

If $iStart >= $iEnd Then ExitLoop
it works lol

So whatever ;) Guest it is resolved :)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...