Jump to content

Arrays


Recommended Posts

This code snippet produces an array of missed Skype Calls.

CODE
;//Process Missed Calls

Dim $callarray[1][2]

Dim $i = 0

For $oCall In $oSkype.MissedCalls

ReDim $callarray[$i + 1][2]

$callarray[$i][0] = $oCall.id

$callarray[$i][1] = $oCall.PartnerHandle

$CountCalls = $CountCalls + 1

$oSkypeMissedCallsName = $callarray[$i][1] & "," & $oSkypeMissedCallsName

$i += 1

Next

The array can contain more than one appearance of the Skype Name [partnerhandle] each Skype Name including duplicates has its own id.

The script currently compiles a comma separated string which looks like this:

"smith,jones,wilson,rudd,jones,smith"

How would you count the number of appearances of the skype name in $oSkypeMissedCallsName and recompile it so that the string would appear as follows

"[2] smith, [2] jones, [1] wilson, [1] rudd"

Help is always appreciated. Ant.. muttley

Link to comment
Share on other sites

_ArrayUnique()

EDIT: and if you wanted the count thingy you can count them by cycling through them first

#include <Array.au3>
Dim $Array[6] = ["smith","jones","wilson","rudd","jones","smith"]

Dim $Count[Ubound($Array)]
For $a= 0 to UBound($Count)-1
    $Count[$a]= 0
Next
For $x1 = 0 to Ubound($Array)-1
    For $x2 = 0 to UBound($Array)-1
        if $Array[$x1] = $Array[$x2] then $Count[$x1]+=1
    Next
Next
For $I = 0 to UBound($Array)-1
    $Array[$i] = "{"&$Count[$i]&"} "&$Array[$i]
Next
_ArrayDisplay($Count)
$Array = _ArrayUnique($Array)
_ArrayDisplay($Array)


;ArrayUnique by litlmike & Smoke_N
Func _ArrayUnique($aArray, $iDimension = 1, $iBase = 0, $iCase = 0, $vDelim = "|")
    ;$aArray used to be ByRef, but litlmike altered it to allow for the choosing of 1 Array Dimension, without altering the original array
    If $vDelim = "|" Then $vDelim = Chr(01) ; by SmOke_N, modified by litlmike
    If Not IsArray($aArray) Then Return SetError(1, 0, 0) ;Check to see if it is valid array
   
    ;Checks that the given Dimension is Valid
    If Not $iDimension > 0 Then
        Return SetError(3, 0, 0) ;Check to see if it is valid array dimension, Should be greater than 0
    Else
        ;If Dimension Exists, then get the number of "Rows"
        $iUboundDim = UBound($aArray, 1) ;Get Number of "Rows"
        If @error Then Return SetError(3, 0, 0) ;2 = Array dimension is invalid.
       
        ;If $iDimension Exists, And the number of "Rows" is Valid:
        If $iDimension > 1 Then ;Makes sure the Array dimension desired is more than 1-dimensional
            Dim $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
            For $i = 0 To $iUboundDim - 1 ;Loop through "Rows"
                _ArrayAdd($aArrayTmp, $aArray[$i][$iDimension - 1]) ;$iDimension-1 to match Dimension
            Next
            _ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
        Else ;Makes sure the Array dimension desired is 1-dimensional
            ;If Dimension Exists, And the number of "Rows" is Valid, and the Dimension desired is not > 1, then:
            ;For the Case that the array is 1-Dimensional
            If UBound($aArray, 0) = 1 Then ;Makes sure the Array is only 1-Dimensional
                Dim $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
                For $i = 0 To $iUboundDim - 1
                    _ArrayAdd($aArrayTmp, $aArray[$i])
                Next
                _ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
            Else ;For the Case that the array is 2-Dimensional
                Dim $aArrayTmp[1] ;Declare blank array, which will hold the dimension declared by user
                For $i = 0 To $iUboundDim - 1
                    _ArrayAdd($aArrayTmp, $aArray[$i][$iDimension - 1]) ;$iDimension-1 to match Dimension
                Next
                _ArrayDelete($aArrayTmp, 0) ;Get rid of 1st-element which is blank
            EndIf
        EndIf
    EndIf
   
    Local $sHold ;String that holds the Unique array info
    For $iCC = $iBase To UBound($aArrayTmp) - 1 ;Loop Through array
        ;If Not the case that the element is already in $sHold, then add it
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArrayTmp[$iCC] & $vDelim, $iCase) Then _
                $sHold &= $aArrayTmp[$iCC] & $vDelim
    Next
    If $sHold Then
        $aArrayTmp = StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim, 1) ;Split the string into an array
        Return $aArrayTmp ;SmOke_N's version used to Return SetError(0, 0, 0)
    EndIf
    Return SetError(2, 0, 0) ;If the script gets this far, it has failed
EndFunc   ;==>_ArrayUnique
Edited by Paulie
Link to comment
Share on other sites

poco moss simpley

$string = "smith,jones,wilson,rudd,jones,smith"

MsgBox(0x0, "...thanks Val ", Set_Missed_Count($string))


Func Set_Missed_Count($str)
    Local $count, $final = "", $split = StringSplit($str, ",")
    For $X = 1 To UBound($split) - 1
        $count = ""
        For $i = $X To UBound($split) - 1
            If StringInStr($final, $split[$i]) Then ContinueLoop
            If StringInStr($split[$X], $split[$i]) Then $count += 1
        Next
        If $count >= 1 Then $final &= ",[" & $count & "] " & $split[$X]
    Next
    Return StringTrimLeft($final, 1)
EndFunc   ;==>Set_Missed_Count

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

poco moss simpley

$string = "smith,jones,wilson,rudd,jones,smith"

MsgBox(0x0, "...thanks Val ", Set_Missed_Count($string))


Func Set_Missed_Count($str)
    Local $count, $final = "", $split = StringSplit($str, ",")
    For $X = 1 To UBound($split) - 1
        $count = ""
        For $i = $X To UBound($split) - 1
            If StringInStr($final, $split[$i]) Then ContinueLoop
            If StringInStr($split[$X], $split[$i]) Then $count += 1
        Next
        If $count >= 1 Then $final &= ",[" & $count & "] " & $split[$X]
    Next
    Return StringTrimLeft($final, 1)
EndFunc   ;==>Set_Missed_Count

8)

Yeah yeah show me up with your simpler code... muttley

EDIT: I used curly brackets. MINES BETTER!! :(:)

Edited by Paulie
Link to comment
Share on other sites

Thanks Paulie:

I have added this to the code + the Function _ArrayUnique:

_ArrayDisplay($callarray, "Missed Calls")

$aNewArray = _ArrayUnique($callarray) ;Using Default Parameters

_ArrayDisplay($aNewArray, "$aNewArray represents the 1st Dimension of $aArray")

This returns the 0 Column ie the id of the caller as there is no duplicate record you get the full listing, how do I get the routine to work on Column 1

which contains the unique name of the caller?

Ant..

Link to comment
Share on other sites

Yeah yeah show me up with your simpler code... muttley

EDIT: I used curly brackets. MINES BETTER!! :(:)

.... :dance:

Actually, I always try to consider what my overhead is with includes.

....so your script is actually "very much longer than mine".

curly's or not ... :P

lol

8)

NEWHeader1.png

Link to comment
Share on other sites

Thanks guys, for the record they both work nicely which just proves that there is always a practical as well as elegant solution to any problem.

Based on your comments I will leave you with the practical elegant discussion. Anyway thanks for the help it was very much appreciated. Ant.. muttley

Link to comment
Share on other sites

This code snippet produces an array of missed Skype Calls.

CODE
;//Process Missed Calls

Dim $callarray[1][2]

Dim $i = 0

For $oCall In $oSkype.MissedCalls

ReDim $callarray[$i + 1][2]

$callarray[$i][0] = $oCall.id

$callarray[$i][1] = $oCall.PartnerHandle

$CountCalls = $CountCalls + 1

$oSkypeMissedCallsName = $callarray[$i][1] & "," & $oSkypeMissedCallsName

$i += 1

Next

The array can contain more than one appearance of the Skype Name [partnerhandle] each Skype Name including duplicates has its own id.

The script currently compiles a comma separated string which looks like this:

"smith,jones,wilson,rudd,jones,smith"

How would you count the number of appearances of the skype name in $oSkypeMissedCallsName and recompile it so that the string would appear as follows

"[2] smith, [2] jones, [1] wilson, [1] rudd"

Help is always appreciated. Ant.. muttley

This is what the code now looks like:

CODE
;//Process Missed Calls, Messages and Voicemail:

Func _SkypeCOM_MissedCalls()

;//Process Missed Calls

Dim $callarray[1][2]

Dim $i = 0

For $oCall In $oSkype.MissedCalls

ReDim $callarray[$i + 1][2]

$callarray[$i][1] = $oCall.PartnerHandle

$oSkypeMissedCallsName = $callarray[$i][1] & "," & $oSkypeMissedCallsName

$i += 1

Next

;//Count the Number of Missed Calls:

For $a = 0 To UBound($callarray) - 1

$CountCalls = $CountCalls + 1

Next

;//Count and delete duplicate records:

$string = $oSkypeMissedCallsName

$MissedCallsFlag = 1

Set_Missed_Count($string)

If $countcalls = 1 Then $MissedNameCalls = " Nil"

;//Process Missed Messages

Dim $msgarray[1][2]

Dim $i = 0

For $oMsg In $oSkype.MissedMessages

ReDim $msgarray[$i + 1][2]

$msgarray[$i][1] = $oMsg.PartnerHandle

$oSkypeMissedMsgsName = $msgarray[$i][1] & "," & $oSkypeMissedMsgsName

$i += 1

Next

;//Count the Number of Missed Messages:

For $a = 0 To UBound($msgarray) - 1

$CountMsgs = $CountMsgs + 1

Next

;//Count and delete duplicate records:

$string = $oSkypeMissedMsgsName

$MissedCallsFlag = 2

Set_Missed_Count($string)

If $countMsgs = 1 Then $MissedNameMsgs = " Nil"

;//Process Voicemail

Dim $voicearray[1][2]

Dim $i = 0

For $oVoice In $oSkype.Voicemails

ReDim $voicearray[$i + 1][2]

$voicearray[$i][1] = $oVoice.PartnerHandle

$oSkypeVoiceName = $voicearray[$i][1] & "," & $oSkypeVoiceName

$i += 1

Next

For $a = 0 To UBound($voicearray) - 1

$CountVoice = $CountVoice + 1

Next

$string = $oSkypeVoiceName

$MissedCallsFlag = 3

Set_Missed_Count($string)

If $CountVoice = 1 Then $MissedNameVoice = " Nil"

EndFunc ;==>_SkypeCOM_MissedCalls

;//Compile the Missed Calls, Messages and Voicemail

Func Set_Missed_Count($str)

Local $count, $name = "", $split = StringSplit($str, ",")

For $X = 1 To UBound($split) - 1

$count = ""

For $i = $X To UBound($split) - 1

If StringInStr($name, $split[$i]) Then ContinueLoop

If StringInStr($split[$X], $split[$i]) Then $count += 1

Next

If $count >= 1 Then $name &= " [" & $count & "] " & $split[$X]

Next

If $MissedCallsFlag = 1 Then $MissedNameCalls = $name

If $MissedCallsFlag = 2 Then $MissedNameMsgs = $name

If $MissedCallsFlag = 3 Then $MissedNameVoice = $name

$MissedCallsFlag = 0

EndFunc

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