Jump to content

shorter array delete


Recommended Posts

Is there any possible way to delete part of an array but with a shorter script then _ArrayDelete().. I need to make a script independant of includes and standalone (one function if possible), but when i had the _Arraydelete() code, it's way too big

e.g. this times 7x

$avArray = $nArray
    $iElement = 0
    $iUpper = UBound($avArray)  
    $iCntr = 0
    If $iUpper = 1 Then
        Local $avNewArray[$iUpper - 1]
        If $iElement < 0 Then
            $iElement = 0
        EndIf
        If $iElement > ($iUpper - 1) Then
            $iElement = ($iUpper - 1)
        EndIf
        If $iElement > 0 Then
            For $iCntr = 0 To $iElement - 1
                $avNewArray[$iCntr] = $avArray[$iCntr]
            Next
        EndIf
        If $iElement < ($iUpper - 1) Then
            For $iCntr = ($iElement + 1) To ($iUpper - 1)
                $avNewArray[$iCntr - 1] = $avArray[$iCntr]
            Next
        EndIf
        $avArray = $avNewArray
    EndIf
Edited by mrRevoked
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

  • Moderators

Is there any possible way to delete part of an array but with a shorter script then _ArrayDelete().. I need to make a script independant of includes and standalone (one function if possible), but when i had the _Arraydelete() code, it's way too big

e.g. this times 7x

$avArray = $nArray
    $iElement = 0
    $iUpper = UBound($avArray)  
    $iCntr = 0
    If $iUpper = 1 Then
        Local $avNewArray[$iUpper - 1]
        If $iElement < 0 Then
            $iElement = 0
        EndIf
        If $iElement > ($iUpper - 1) Then
            $iElement = ($iUpper - 1)
        EndIf
        If $iElement > 0 Then
            For $iCntr = 0 To $iElement - 1
                $avNewArray[$iCntr] = $avArray[$iCntr]
            Next
        EndIf
        If $iElement < ($iUpper - 1) Then
            For $iCntr = ($iElement + 1) To ($iUpper - 1)
                $avNewArray[$iCntr - 1] = $avArray[$iCntr]
            Next
        EndIf
        $avArray = $avNewArray
    EndIf
What does the size of the UDF have to do with anything?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Is there any possible way to delete part of an array but with a shorter script then _ArrayDelete().. I need to make a script independant of includes and standalone (one function if possible), but when i had the _Arraydelete() code, it's way too big

e.g. this times 7x

code of _ArrayDelete: without comments and the stuff needed for a UDF it's about 15 lines of code! If that's way too big, nobody can help you ...

Oh, btw. if _ArrayDelete extends your code by 7x, then your code would have been 15/7 = 2,1428571428571428571428571428571 lines, or with the original code of _ArrayDelete() it's: 38/7 = 5,4285714285714285714285714285714 lines of code.

I really don't know what you are talking about :P

Just use _ArrayDelete() !! It's there, it works and it's short!

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

code of _ArrayDelete: without comments and the stuff needed for a UDF it's about 15 lines of code! If that's way too big, nobody can help you ...

Oh, btw. if _ArrayDelete extends your code by 7x, then your code would have been 15/7 = 2,1428571428571428571428571428571 lines, or with the original code of _ArrayDelete() it's: 38/7 = 5,4285714285714285714285714285714 lines of code.

I really don't know what you are talking about :P

Just use _ArrayDelete() !! It's there, it works and it's short!

Cheers

Kurt

um seriously i meant that _Arraydelete times 7, not the actuall code lol!

15x7 = 225 + 130 = 355 for a single function, I'm talking about having ArrayDelete it atleast 5 lines, like this..

$sArray[5] = $sArray[5,'hello','hi,'hey']

$oldArray = sArray[0]

$sArray[1] = ''

Redim sArray[$oldArray-1]

or something..

Edited by mrRevoked
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

Well a lot of the bulk of arraydelete is probably error checking. ie: Making sure the variable is actually an array, making sure you don't try to delete an item when there only is ONE item, etc. If you're not worried about this extra security, then writing an array item deleting function is really quite simple. In fact, with your little blurb of code there, you're halfway there.

Try this:

Func DelItem(ByRef $aArray, $iItem)
    $iSize = UBound($aArray)
    For $i = $iItem to $iSize - 2
        $aArray[$i] = $aArray[$i + 1]
    Next
    ReDim $aArray[$iSize - 1]
EndFuncoÝ÷ ØLZ^jëh×6Dim $stooges[4] = ['Larry', 'Moe', 'Groucho', 'Curly']

DelItem($stooges, 2)

*Edit: Just know what if you toss garbage at that function it'll die and you won't know why.

Edited by Saunders
Link to comment
Share on other sites

Well a lot of the bulk of arraydelete is probably error checking. ie: Making sure the variable is actually an array, making sure you don't try to delete an item when there only is ONE item, etc. If you're not worried about this extra security, then writing an array item deleting function is really quite simple. In fact, with your little blurb of code there, you're halfway there.

Try this:

Func DelItem(ByRef $aArray, $iItem)
    $iSize = UBound($aArray)
    For $i = $iItem to $iSize - 2
        $aArray[$i] = $aArray[$i + 1]
    Next
    ReDim $aArray[$iSize - 1]
EndFuncoÝ÷ ØLZ^jëh×6Dim $stooges[4] = ['Larry', 'Moe', 'Groucho', 'Curly']

DelItem($stooges, 2)

*Edit: Just know what if you toss garbage at that function it'll die and you won't know why.

hey, just dropping by to say it worked.. Saunders, i think i can devise a way to avoid problems.. anyways im ashtonished you got it 5 in lines lol, thanks
Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()
Link to comment
Share on other sites

No prob. I've found a lot of code can be written shorter, at the expense of losing a few details, but as long as you know you'll be using the function without invalid parameters then you don't need to worry.

Thats what they all think when writing the stuff. Ever heard of blue screen?
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...