Sign in to follow this  
Followers 0
anixon

arrays

4 posts in this topic

After displaying an 2 dimension array like:

_arraydisplay($array)

[0] 3

[1] "text1"

[2] "text2"

[3] "Text3"

How do I then clear all the contents of the array so that if it was displayed again it would look like

_arraydisplay($array)

[0] 0

is there a single command or do you have to use _arraydelete($array) in a loop and uBound to set [0] to 0

Help is always appreciated

Ant..

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

After displaying an 2 dimension array like:

_arraydisplay($array)

[0] 3

[1] "text1"

[2] "text2"

[3] "Text3"

How do I then clear all the contents of the array so that if it was displayed again it would look like

_arraydisplay($array)

[0] 0

is there a single command or do you have to use _arraydelete($array) in a loop and uBound to set [0] to 0

Help is always appreciated

Ant..

1. That's an example of a 1 dimensional array, not a 2.

2. You'd have to write the condition I suppose lol... I personally wouldn't have [0] = anything.

This example should clear up to a 4 dimensional array:

Func _ClearArray(ByRef $avArray)
    Switch UBound($avArray, 0)
        Case 1
            ReDim $avArray[UBound($avArray)]
        Case 2
            ReDim $avArray[UBound($avArray, 1)][UBound($avArray, 2)]
        Case 3
            ReDim $avArray[UBound($avArray, 1)][UBound($avArray, 2)] _
                [UBound($avArray, 3)]
        Case 4
            ReDim $avArray[UBound($avArray, 1)][UBound($avArray, 2)] _
                [UBound($avArray, 3)][UBound($avArray, 4)]
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch
    Return 1
EndFunc
Edited by SmOke_N

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.

Share this post


Link to post
Share on other sites

A simple Dim $array will do the trick.

When using Dim it will set the new UBound and clear the values.

Here is a small example:

#include <array.au3>
Dim $array[3]
$array[0]=2
$array[1]=15
$array[2]=66
_ArrayDisplay($array)
Dim $array[1]
$array[0] = 0
_ArrayDisplay($array)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

A simple Dim $array will do the trick.

When using Dim it will set the new UBound and clear the values.

Here is a small example:

#include <array.au3>
Dim $array[3]
$array[0]=2
$array[1]=15
$array[2]=66
_ArrayDisplay($array)
Dim $array[1]
$array[0] = 0
_ArrayDisplay($array)
Thanks for that works perfectly.

Ant..

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  
Followers 0