Jump to content

Array anomily...


Recommended Posts

Well here's something strange.

Why does this not work:

Func _ArySrchDel($array, $word, $case, $column)
    $r = 0
    While $r = 0
        $todelete = _ArraySearch($array, $word, 0, 0, $case, 0, 1, $column)
            If @error Then
                $r = 1
            Else
                MsgBox(1,"This is being deleted",$todelete & " Which is " & $word)
                _ArrayDelete($array, $todelete)
                    If @error Then
                        $r = 1
                        msgbox(1,"Error","Did not delete " & $word & "." & @error)
                    Else
                        $r = 0
                        msgbox(1,"Success","Entry " & $word & " deleted.")
                    EndIf
            Endif
    WEnd
EndFunc

_ArySrchDel($aLinks,"Similar",1,5)

but this does:

While $r = 0
        $todelete = _ArraySearch($aLinks, "Similar", 0, 0, 1, 0, 1, 5)
            If @error Then
                $r = 1
            Else
                MsgBox(1,"This is being deleted",$todelete & " Which is " & "Similar")
                _ArrayDelete($aLinks, $todelete)
                    If @error Then
                        $r = 1
                        msgbox(1,"Error","Did not delete " & "Similar" & ". " & @error)
                    Else
                        $r = 0
                        msgbox(1,"Success","Entry " & "Similar" & " deleted.")
                    EndIf
            Endif
    WEnd

Here's all the code I'm tinkering with. Take note of the includes:

#include <ff.au3>
#include <file.au3>
#Include <Array.au3>


$line = 1
$File = "words.txt"
$Numberoflines = _FileCountLines($File)
$aLinks = 0
$r = 0
$todelete = 0

Func _ArySrchDel($array, $word, $case, $column)
    $r = 0
    While $r = 0
        $todelete = _ArraySearch($array, $word, 0, 0, $case, 0, 1, $column)
            If @error Then
                $r = 1
            Else
                MsgBox(1,"This is being deleted",$todelete & " Which is " & $word)
                _ArrayDelete($array, $todelete)
                    If @error Then
                        $r = 1
                        msgbox(1,"Error","Did not delete " & $word & "." & @error)
                    Else
                        $r = 0
                        msgbox(1,"Success","Entry " & $word & " deleted.")
                    EndIf
            Endif
    WEnd
EndFunc

While $line < $Numberoflines
    $Words = FileOpen($File)
    $stringread = FileReadLine($Words,$line)
    FileClose($Words)
    $line += 1
    _FFStart("www.google.com")
    WinWaitActive("Google - Mozilla Firefox")
    sleep(1000)
    ControlSend("Google - Mozilla Firefox","","",$stringread & "{ENTER}")
    Sleep(3000)
    $aLinks = _FFLinksGetAll()
    _ArraySort($aLinks, 1, 0, 0, 5)
    sleep(250)
    ;_ArySrchDel($aLinks,"Similar",1,5)
    ;_ArySrchDel($aLinks,"Cached",1,5)
    ;_ArySrchDel($aLinks,"mail",1,5)
    ;_ArySrchDel($aLinks,"Gmail",1,5)
    ;_ArySrchDel($aLinks,"sign in",1,5)
    ;_ArySrchDel($aLinks,"similar",1,5)
    While $r = 0
        $todelete = _ArraySearch($aLinks, "Similar", 0, 0, 1, 0, 1, 5)
            If @error Then
                $r = 1
            Else
                MsgBox(1,"This is being deleted",$todelete & " Which is " & "Similar")
                _ArrayDelete($aLinks, $todelete)
                    If @error Then
                        $r = 1
                        msgbox(1,"Error","Did not delete " & "Similar" & ". " & @error)
                    Else
                        $r = 0
                        msgbox(1,"Success","Entry " & "Similar" & " deleted.")
                    EndIf
            Endif
    WEnd
    _ArrayDisplay($aLinks)
    $line +=1
WEnd

Now to the more specifics.

I am getting all the links from a normal google web search into an array of info. (for example I am searching google for "yahoo") From there I am sorting, then searching the array for all instances of the word "Similar" in column 5 and then deleting them.

I wanted to make a function that would allow me to input which words I want to filter out quickly. The first code about holds the function which reports through msgbox that it is deleting the entries just fine. That is not the case as the array still has entries with the word "Similar" in column 5.

The second code is basically the same thing as the function just without the function :blink:. (all values are input manually) It works just fine.

Is it that I am using the same variables in the function is causing problems? I just can't figure this one out!

For those who don't have ff.au3 I included it below. Make sure to also get Mozrepl. (quick google can set you up on that one.)

words.txt

FF.au3

Edited by Kaeft
Link to comment
Share on other sites

Your function doesn't return anything. Either make the array ByRef in your function definition, or Return it using the return keyword.

(didn't test, but I assume that would cause trouble)

Wow ok that was way too simple. I am still learning (quite a lot as I go along, mostly by reading the help) so I have never heard of ByRef. And now I just read it. I would never have picked up on that. Cool thanks a bunch!

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...