Jump to content

Help with multi-dimensional arrays.


 Share

Recommended Posts

I'm fairly new to this multi-dim arrays part and I realized the potentials of storing more data for 2nd dimensional array and is suited for my task. What I am trying to do is creating unlimited amount of dimensions for names & subject whitelist filters from a text file for emails (3 elements as in 2nd dimensional such as: [0] = Names or "@subject", [1] = Subject's filter name, [2] = Target folder names) like this and use " -> " to sort emails to target folders:

From a text file:

@subject New Message:
@subject [group] -> Group Emails
John Doe
myemail@anywhere.com
Tom Warren -> Friends
Jessica White
Mike Shaw -> Business
Jon & Jane Williams

To:

;@subject New Message:
$FilteredWhitelist[0][0];@subject
$FilteredWhitelist[0][1];New Message:
$FilteredWhitelist[0][2];"" (blank)

;@subject [group] -> Group Emails
$FilteredWhitelist[1][0];@subject
$FilteredWhitelist[1][1];[group]
$FilteredWhitelist[1][2];Group Emails

;John Doe
$FilteredWhitelist[2][0];John Doe
$FilteredWhitelist[2][1];"" (blank)
$FilteredWhitelist[2][2];"" (blank)

;myemail@anywhere.com
$FilteredWhitelist[3][0];myemail@anywhere.com
$FilteredWhitelist[3][1];"" (blank)
$FilteredWhitelist[3][2];"" (blank)

;Tom Warren -> Friends
$FilteredWhitelist[4][0];Tom Warren
$FilteredWhitelist[4][1];"" (blank)
$FilteredWhitelist[4][2];Friends

~so on

However, I could not get this to work:

Dim $whitelist[1], $FilteredWhitelist[1], $tempsearch[1]

_GetWhitelist()

ReDim $FilteredWhitelist[UBound($FilteredWhitelist) + 1][3];Adjust the compare array size to accomodate new values
For $j = 1 To $whitelist[0]
    $search = $whitelist[$j]
    
    Select
        Case StringInStr($search, "@subject ");Searching for "@subject "
            $FilteredWhitelist[UBound($FilteredWhitelist) - 1][0] = "@subject"
            $search = StringReplace($search, "@subject ", "") ;Remove "@subject "
            If StringInStr($search, " -> ") Then ;Searching for " -> "
                $tempsearch = StringRegExp($search, "((?: -> )([:alnum:].*))", 1);Extract anything after " -> "
                If Not $tempsearch = "" Then
                    $search = $tempsearch[0]
                    $FilteredWhitelist[UBound($FilteredWhitelist) - 1][2] = $search
                EndIf
            Else;No "@subject " or " -> " existed
                $FilteredWhitelist[UBound($FilteredWhitelist) - 1][1] = $search
            EndIf
        Case StringInStr($search, " -> ");Searching for " -> "
            $tempsearch = StringRegExp($search, "(&@[:alnum:].*)(?: -> )", 1);Extract anything before " -> "
            If Not $tempsearch = "" Then
                $search = $tempsearch[0]
                $FilteredWhitelist[UBound($FilteredWhitelist) - 1][0] = $search
            EndIf

            $tempsearch = StringRegExp($search, "((?: -> )([:alnum:].*))", 1)
            If Not $tempsearch = "" Then
                $search = $tempsearch[0]
                $FilteredWhitelist[UBound($FilteredWhitelist) - 1][2] = $search
            EndIf
        Case Else
            $FilteredWhitelist[UBound($FilteredWhitelist) - 1][0] = $search
    EndSelect
    ReDim $FilteredWhitelist[UBound($FilteredWhitelist) + 1][3];Adjust the compare array size to accomodate new values
Next

For $element = 1 to $whitelist[0]
       MsgBox(0, "", $FilteredWhitelist[$element - 1][0] & "," & $FilteredWhitelist[$element - 1][1] & "," & $FilteredWhitelist[$element - 1][2])
Next

Func _GetWhitelist()
;Get whitelist
    $s_Path = @ScriptDir & "\whitelist.txt"
    If Not FileExists($s_Path) Then
        MsgBox(4096, "Error!", "whitelist.txt does not exist. Please create one with at least one filter in it.")
        Exit
    EndIf
    _FileReadToArray($s_Path, $whitelist)
EndFunc 

Func _FileReadToArray($sFilePath, ByRef $aArray)
    Local $hFile
    
    $hFile = FileOpen($sFilePath, 0)
    
    If $hFile = -1 Then
        SetError(1)
        Return 0
    EndIf
    
    $aArray = StringSplit(StringStripCR(FileRead($hFile, FileGetSize($sFilePath))), @LF)
    
    FileClose($hFile)
    Return 1
EndFunc

Also, what is the proper way to do For Next on $FilteredWhitelist multi-dimensional arrays when dealing with unknown element numbers in 1st dimensional array and then checks those 3 elements in 2nd dimensional array each time?

EDIT:

Changed to [ autoit ] code box

Edited by Blackstar
Link to comment
Share on other sites

I have not read your code as the "unlimited" word made me loose interest.

But you could read the wiki tutorial about arrays

Also remember that UBound($arr, $dimention) will help you out..:P

EDIT:

PS: Happy new year..:D

Edited by Uten
Link to comment
Share on other sites

I have downloaded your files and I have tried them. The messagebox shows only some of the persons. It is difficult to follow your code. Try to solve your problems in more little steps and evaluare them. I don't know the function StringRegExp and don't find them in my help file. Sorry, that I can't give you another answer Johannes :P

Johannes LorenzBensheim, Germanyjlorenz1@web.de[post="12602"]Highlightning AutoIt Syntax in Notepad++ - Just copy in your Profile/application data/notepad++[/post]

Link to comment
Share on other sites

I have downloaded your files and I have tried them. The messagebox shows only some of the persons. It is difficult to follow your code. Try to solve your problems in more little steps and evaluare them. I don't know the function StringRegExp and don't find them in my help file. Sorry, that I can't give you another answer Johannes :P

You should update to the latest release. StringRegExp was away in some of the betas due to bugs. But a new version (beta) has been around fore months now.
Link to comment
Share on other sites

I have downloaded your files and I have tried them. The messagebox shows only some of the persons. It is difficult to follow your code. Try to solve your problems in more little steps and evaluare them. I don't know the function StringRegExp and don't find them in my help file. Sorry, that I can't give you another answer Johannes :D

jlorenz1, I commented what does that StringRegExp do in the code, didnt you see it?

Uten, "unlimited" - true...I guess thats the wrong word for it....just say at least up to hundred elements then :P. It just depends on how many names added to the text file...it could start out at 5 names to at least 100 names. Are you able to see what went wrong with the code?

EDIT:

PS, Happy New Year you too!

Edited by Blackstar
Link to comment
Share on other sites

Try to explain what goes wrong. You give no indication on what goes wrong, only what you want. And I'm not in beta testing mode today, sorry..:P

hmm, this does not look good to my eyes UBound($FilteredWhitelist) - 1 although you have a redim in the last part of the code so it might work, but it is definitely not fast..:D

Another tip. Use the [ autoit ] ; code [ /autoit ] tags (remove the spaces). It will make it a lot easier to read your code.

Link to comment
Share on other sites

Ok, changed to [ autoit ]...indeed it does look better - good idea, thanks.

What does not work that I unable to figure out when msgbox says:

,, or @subject,,

when it should say:

@subject, New Message, or @subject, [group], Group Emails

from $whitelist array:

@subject New Message:

@subject [group] -> Group Emails

I have redim in the last part of my code...speed not really the issue for me...I just wanted to work properly.

Make sense?

Edited by Blackstar
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...