Jump to content

Declaration of Variables using For


Recommended Posts

Hello,

i know there is probably another post quite like this with all the answers inside in this forum, but before you flame now plz consider that i searched now for like an hour without finding it :/. My tests havent brought me any further either. So here is my Question. Is it possible to declarate Variables with using for ? Like Arrays or such here the Wrong Version so it might be better understood:

WRONG:

for $i = 1 to 10
global $array{$i}[1]
next

Now i DONT want to make a 2dim Array since the ubound function dosent seem to work with more than 2dim and i thought well i make 6 2dim arrays out of my 1 3dim one. So if anyone could help me with a quick tip i would appreciate that! Thx in Advance

greetz Max

edit: Ok then i cant explain the error but nevertheless the first question would help to automate the thing for different problems so an answer would be nice anyway heres the not working code ( plz dont hit me i know i'm quite bad ^^ and havent commented :/ )

edit 2: the error...

Stage 1 Complete

E:downloadsProgrammeautoitscriptsPixeltest.au3 (40) : ==> Error in expression.:

for $x 0 to (ubound($array,3)-1)

for $x 0 ^ ERROR

>Exit code: 1 Time: 9.008

edit 3: i'M stupid ... forgot the = .... might solve the problem ^^ anyway still corious about the first question ;)

edit 4: now i'm getting this error :/ Any Tips ( since i have that post already ^^ )

Stage 1 Complete

E:downloadsProgrammeautoitPixeltest.au3 (45) : ==> No variable given for "Dim", "Local", "Global", "Struct" or "Const" statement.:

redim($it12[$k])

redim^ ERROR

>Exit code: 1 Time: 8.607

heres the original - with repeatable variable declaration i could caugh the lower block together.. tried fast some explaining comments but since it was just a try if it would work i havent been true with commenting

#include <Array.au3>
#include<File.au3>

HotKeySet("{f1}", "pixel")


Global $array[6][3][144]
Global $It12[1]
Global $It13[1]
Global $It14[1]
Global $It15[1]
Global $It16[1]


while 1
    sleep(500)
wend


func pixel()                                                                ; some fast comments here
        
$x=555                                                                      ; x y position where pixelcheck shall start
$y=359

for $k=0 to 2                                                               ; creating 3dim array with hex checksums
    for $i=0 to 5
        for $j=0 to 23
            $array[$i][$k][$j]=hex(PixelGetColor($x+27*$i+$j ,$y+$k))
        next
    Next
Next

ConsoleWrite("Stage 1 Complete")                                            ; reminder for console to see if it rly runs ;)


$z=0                                                                        ; now i want to check for duplicates ( the goal is to get pixel's which are in all 6 ( first dimension of the array ) Groups !
for $y = 0 to (ubound($array,2)-1)
    for $x =0 to (ubound($array,3)-1)
        for $y2 = 0 To (ubound($array,2)-1)
            for $x2 = 0 To (ubound($array,3)-1)
                if $array[$z][$x][$y] = $array[$z+1][$x2][$y2] Then
                    $k=ubound($it12)-1
                    redim($it12[$k])
                    $It12[$k]=$array[$z][$x][$y]
                EndIf
            Next
        Next
    Next
Next

ConsoleWrite("Stage 2 Complete")                                        

$z=1
for $x = 0 to (ubound($It12)-1)                                             ; Checking the IT12 array against the second Group the rest is the same
    for $y2 = 0 To (ubound($array,2)-1)
        for $x2 = 0 To (ubound($array,3)-1)
            if $It12[$x] = $array[$z+1][$x2][$y2] Then
                $k=ubound($item13)-1
                redim($it13[$k])
                $It13[$k]=$It12[$x]
            EndIf
        Next
    Next
Next

ConsoleWrite("Stage 3 Complete")

$z=2
for $x = 0 to (ubound($Item13)-1)
    for $y2 = 0 To (ubound($array,2)-1)
        for $x2 = 0 To (ubound($array,3)-1)
            if $It13[$x] = $array[$z+1][$x2][$y2] Then
                $k=ubound($it14)-1
                redim($it14[$k])
                $It14[$k]=$It13[$x]
            EndIf
        Next
    Next
Next

ConsoleWrite("Stage 4 Complete")

$z=3
for $x = 0 to (ubound($Item14)-1)
    for $y2 = 0 To (ubound($array,2)-1)
        for $x2 = 0 To (ubound($array,3)-1)
            if $It14[$x] = $array[$z+1][$x2][$y2] Then
                $k=ubound($it15)-1
                redim($it15[$k])
                $It15[$k]=$It14[$x]
            EndIf
        Next
    Next
Next

ConsoleWrite("Stage 5 Complete")

$z=4
for $x = 0 to (ubound($Item15)-1)
    for $y2 = 0 To (ubound($array,2)-1)
        for $x2 = 0 To (ubound($array,3)-1)
            if $It15[$x] = $array[$z+1][$x2][$y2] Then
                $k=ubound($it16)-1
                redim($it16[$k])
                $It16[$k]=$It15[$x]
            EndIf
        Next
    Next
Next



for $i = 0 to (ubound($It16)-1)
    ConsoleWrite($It16[$i] & @LF)
next


#cs  old version for output before i found redim
$string = ""
$string2 = ""
For $i = 0 To UBound($array) - 1
    $o="a"
    $p=0
    For $j = 0 To UBound($array, 2) - 1
        $z=$j-24*$p
        $string &=( "$array[" & $i & "][" & $z & $o &"] = " & $array[$i][$j] & @LF)
        $string2 &=( $array[$i][$j] & @LF)
        if $z>22 Then
            $p=$p+1
            if $p=1 Then
                $o="b"
            elseif $p=2 Then
                $o="c"
            elseif $p=3 Then
                $o="d"
            elseif $p=4 Then
                $o="e"
            elseif $p=5 Then
                $o="f"
            elseif $p=6 Then
                $o="g"
            EndIf
        EndIf
    Next
Next

$hFile = FileOpen(@ScriptDir & "2DArray.txt", 2)
FileWrite($hFile, $string)
FileClose($hFile)
$hFile2 = FileOpen(@ScriptDir & "test.txt", 2)
FileWrite($hFile2, $string2)
FileClose($hFile2)
#ce
endfunc
Edited by Maxel
Link to comment
Share on other sites

  • Moderators

Maxel,

UBound works fine with 3D arrays, so there is no need to split your 3D array. :)

Perhaps if you posted the code you were having trouble with we could help you debug it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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