Jump to content
Sign in to follow this  
hgeras

ArrayPush UDF...

Recommended Posts

hgeras

The functionality is as that: You tell it to to store a new value at the first or the last element and delete the last or first one , depending the direction you chose...So you will have new values and the others will "slide" left or right... You can see a need for application of this function in my NvTempLogger script (check sig) , the Array_Slide_left function...Of course this UDF is more improved since you can choose direction and the new value can also be another array...Consider it the opposite of _ArrayPop UDF....

;=====================================================================================
;
; Function Name:    _ArrayPush
; Description:    Add new values without increasing array size.Either by inserting
;                  at the end the new value and deleting the first one or vice versa.
; Parameter(s):  $avArray     - Array
;                  $sValue     - The new value.It can be an array too.
;                  $i_Direction  - 0 = Leftwise slide (adding at the end) (default)
;                                  1 = Rightwise slide (adding at the start)         
; Requirement(s):   None
; Return Value(s):  On Success -  Returns 1
;                  On Failure -  0 if $avArray is not an array.
;                                -1 if $sValue array size is greater than $avArray size.
;                                In both cases @error is set to 1.
; Author(s):        Helias Gerassimou(hgeras)
;
;======================================================================================



Func _ArrayPush(ByRef $avArray, $sValue, $i_Direction = 0)
    Local $i,$j
    
    If (Not IsArray($avArray)) Then
        SetError(1)
        Return 0
    EndIf
    

If (Not IsArray($sValue)) Then  
    If $i_Direction = 1 Then
        For $i = (UBound($avArray) - 1) To 1
            $avArray[$i] = $avArray[$i - 1]
        Next
        $avArray[0] = $sValue
        
    Else
        
        For $i = 0 To (UBound($avArray) - 2)
            $avArray[$i] = $avArray[$i + 1]
        Next
        Local $i = (UBound($avArray) - 1)
        $avArray[$i] = $sValue
        
    EndIf
    
    SetError(0)
    Return 1
Else
    If UBound($sValue) > UBound($avArray) Then
        Seterror(1)
        Return -1
    Else
    
    For $j = 0 to (UBound($sValue) - 1)
        If $i_Direction = 1 Then
            For $i = (UBound($avArray) - 1) To 1
                $avArray[$i] = $avArray[$i - 1]
            Next
            $avArray[$j] = $sValue[$j]
        
        Else
        
            For $i = 0 To (UBound($avArray) - 2)
                $avArray[$i] = $avArray[$i + 1]
            Next
            Local $i = (UBound($avArray) - 1)
            $avArray[$i] = $sValue[$j]
        
        EndIf
    Next
    EndIf
EndIf
    
    SetError(0)
    Return 1
    
    
EndFunc  ;==>_ArrayPush

I hope you make a good use of it....

C ya

Share this post


Link to post
Share on other sites
busysignal

Interesting use of an array.. :dance:

Cheers.. :whistle:

Share this post


Link to post
Share on other sites
busysignal

Sweeet...... Nice to see good code put into the product..

I have to get the latest beta. I know there was a project to check for new beta but not sure where it went. So, I guess I will have to make my own. :dance:

Thanks for the update.. and will check it out..

Cheers.. :whistle:

Share this post


Link to post
Share on other sites
theguy0000

interesting script...nice :dance:

(i accidentaly deleted my original post :whistle:)


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

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  

×