Jump to content

problem in array simple script


Recommended Posts

Hi there,

i just tried to make a simple upgrade of an array script : here it is :

#include <Array.au3>

Local $arr[4]

Dim $a1

_ArrayAdd($a1, "toto")

_ArrayAdd($a1, "titi")

Dim $a11[3] = [2,"toto1","titi1"]

Local $a2[3] = [2, "a2-1","a2-2"]

$arr[1] = $a1

$arr[2] = $a11

$arr[3] = $a2

$arr[0] = 3

Local $i , $j

Local $dumy

For $i = 1 to $arr[0]

$dumy = $arr[$i]

If IsArray($dumy) Then

For $j = 1 to $dumy[0] - 1

_ArrayDisplay($dumy, "_ArrayDisplay() Test")

Next

Else

ConsoleWrite("!UPS, What happened? Expected an array" & @LF)

EndIf

Next

It seems it only wants to show me a11 and a2, why doesnt he wants to show me a1 ?

(i think i dont know also how to use redim ...)

Thanks for helping.

Mr Pook

Link to comment
Share on other sites

Because you didn't declare $a1 as an array

#include <Array.au3>

Local $arr[4]
Dim $a1[1]
_ArrayAdd($a1, "toto")
_ArrayAdd($a1, "titi")
Dim $a11[3] = [2,"toto1","titi1"]
Local $a2[3] = [2, "a2-1","a2-2"]
$arr[0] = 3
$arr[1] = $a1[1]
$arr[2] = $a11[2]
$arr[3] = $a2[2]
Local $i , $j
Local $dumy[$arr[0]]
MsgBox (0, $arr[0],$arr[0])
MsgBox(0, $arr[1], $arr[2])
For $i = 1 to $arr[0]
$dumy[$i - 1] = $arr[$i]
Next
If IsArray($dumy) Then
_ArrayDisplay($dumy, "_ArrayDisplay() Test")
Else
ConsoleWrite("!UPS, What happened? Expected an array" & @LF)
EndIf
Link to comment
Share on other sites

Hi,

I think he wants to make a number of arrays?

; _ArrayAddPook.au3
#include <Array.au3>
Local $arr[4]
Dim $a1[1], $a11[1], $a2[1]
_ArrayAdd($a1, "toto")
_ArrayAdd($a1, "titi")
_ArrayDisplay($a1, "_ArrayDisplay() $a1")
Dim $a11[3] = [2, "toto1", "titi1"]
Local $a2[3] = [2, "a2-1", "a2-2"]
$arr[1] = $a1
$arr[2] = $a11
$arr[3] = $a2
$arr[0] = 3
_ArrayDisplay($arr, "_ArrayDisplay() $arr - this will not display as each element is an array")
Local $i, $j
Local $dumy
For $i = 1 To $arr[0]
    $dumy = $arr[$i]
    If IsArray($dumy) Then
        _ArrayDisplay($dumy, "_ArrayDisplay() $dumy Array=" & $i)
    Else
        ConsoleWrite("!UPS, What happened? Expected an array" & @LF)
    EndIf
Next
Randall
Link to comment
Share on other sites

Hi,

I think he wants to make a number of arrays?

; _ArrayAddPook.au3
#include <Array.au3>
Local $arr[4]
Dim $a1[1], $a11[1], $a2[1]
_ArrayAdd($a1, "toto")
_ArrayAdd($a1, "titi")
_ArrayDisplay($a1, "_ArrayDisplay() $a1")
Dim $a11[3] = [2, "toto1", "titi1"]
Local $a2[3] = [2, "a2-1", "a2-2"]
$arr[1] = $a1
$arr[2] = $a11
$arr[3] = $a2
$arr[0] = 3
_ArrayDisplay($arr, "_ArrayDisplay() $arr - this will not display as each element is an array")
Local $i, $j
Local $dumy
For $i = 1 To $arr[0]
    $dumy = $arr[$i]
    If IsArray($dumy) Then
        _ArrayDisplay($dumy, "_ArrayDisplay() $dumy Array=" & $i)
    Else
        ConsoleWrite("!UPS, What happened? Expected an array" & @LF)
    EndIf
NextoÝ÷ Ù§u©eþ«¨µëajy2¢çè®Øb±ø«²Ø^§vz0ÚòyÜ"¶.¶IèÂ)ටºfÞ®Ú®¶²²,Ûh¦ëbMújºÚÛkçm+ºÚ"µÍÈÐ^PYÛÚË]LÂÚ[ÛYH  Ð^K]LÉÝÂ[H  ÌÍØÌWB[H    ÌÍØLVÌWK    ÌÍØLLVÌWK   ÌÍØLÌWBÐ^PY
    ÌÍØLK    ][ÝÝÝÉ][ÝÊBÐ^PY
    ÌÍØLK    ][ÝÝ]I][ÝÊBÐ^^J ÌÍØLK    ][Ý×Ð^^J
H   ÌÍØLI][ÝÊB[H   ÌÍØLLVÌ×HHÌ   ][ÝÝÝÌI][ÝË   ][ÝÝ]LI][Ý×BØØ[   ÌÍØLÌ×HHÌ ][ÝØLLI][ÝË ][ÝØLL][Ý×BÐ^PY
    ÌÍØ  ÌÍØLJBÐ^PY
    ÌÍØ  ÌÍØLLJBÐ^PY
    ÌÍØ  ÌÍØLBÉÌÍØÌWHH   ÌÍØLBÉÌÍØÌHH    ÌÍØLLBÉÌÍØÌ×HH ÌÍØLÉÌÍØÌHHÂ×Ð^^J ÌÍØ  ][Ý×Ð^^J
H   ÌÍØHÈÚ[ÝÜ^HÈXXÚ[[Y[È[^I][ÝÊBØØ[   ÌÍÚK ÌÍÚØØ[ ÌÍÙ[^BÜ ÌÍÚHHHÈ ÌÍØÌB   ÌÍÙ[^HH  ÌÍØÉÌÍÚWBYÐ^J   ÌÍÙ[^JH[Ð^^J ÌÍÙ[^K   ][Ý×Ð^^J
H   ÌÍÙ[^H^OI][ÝÈ  [È ÌÍÚJB[ÙBÛÛÛÛUÜ]J   ][ÝÉÌÌÎÕTËÚ][^XÝY[^I][ÝÈ  [ÈB[Y^

but it didnt work, i think i messed it again because $arr is not displayed anymore.

*sigh*

Link to comment
Share on other sites

but it didnt work, i think i messed it again because $arr is not displayed anymore.

*sigh*

You are declaring an array, then declaring it again, which is unnecessary.

They are not being declared inside a function, so LOCAL is useless, just go with DIM.

The count is not in $arr[0] automatically, you have to put there with Ubound().

This works:

; _ArrayAddPook.au3
#include <Array.au3>

Dim $arr[1], $a1[1], $a2[3] = [2, "a2-1", "a2-2"]
Dim $a11[3] = [2, "toto1", "titi1"]
Dim $dumy

_ArrayAdd($a1, "toto")
_ArrayAdd($a1, "titi")
_ArrayDisplay($a1, "_ArrayDisplay() $a1")

_ArrayAdd($arr, $a1)
_ArrayAdd($arr, $a11)
_ArrayAdd($arr, $a2)
$arr[0] = UBound($arr) - 1

For $i = 1 To $arr[0]
    $dumy = $arr[$i]
    If IsArray($dumy) Then
        _ArrayDisplay($dumy, "_ArrayDisplay() $dumy Array=" & $i)
    Else
        ConsoleWrite("!UPS, What happened? Expected an array" & @LF)
    EndIf
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You are declaring an array, then declaring it again, which is unnecessary.

They are not being declared inside a function, so LOCAL is useless, just go with DIM.

The count is not in $arr[0] automatically, you have to put there with Ubound().

This works:

; _ArrayAddPook.au3
#include <Array.au3>

Dim $arr[1], $a1[1], $a2[3] = [2, "a2-1", "a2-2"]
Dim $a11[3] = [2, "toto1", "titi1"]
Dim $dumy

_ArrayAdd($a1, "toto")
_ArrayAdd($a1, "titi")
_ArrayDisplay($a1, "_ArrayDisplay() $a1")

_ArrayAdd($arr, $a1)
_ArrayAdd($arr, $a11)
_ArrayAdd($arr, $a2)
$arr[0] = UBound($arr) - 1

For $i = 1 To $arr[0]
    $dumy = $arr[$i]
    If IsArray($dumy) Then
        _ArrayDisplay($dumy, "_ArrayDisplay() $dumy Array=" & $i)
    Else
        ConsoleWrite("!UPS, What happened? Expected an array" & @LF)
    EndIf
Next

:)

Thank you so much for helping, this was the tiny part where i was stuck, now everything is ok (so far)

MrPook

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