Jump to content

arrays


anixon
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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 :)

Link to comment
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..

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