Jump to content
Sign in to follow this  

Multidimensional arrays with different sizes

Recommended Posts

Can a Multidimensional array be with different sizes? It's possible to declare them?

Like this:


instead of the usual $s[2][3] with 2 rows of 3 elements?

Share this post

Link to post
Share on other sites

Your syntax is wrong...

$s[2][3] = [[1,2],[3,4,5]]

// then you can redim it like this

redim $s[2][2]

Pist...Use a declaration keyword to declare an array else you may get a syntax error. :mellow:

Share this post

Link to post
Share on other sites

niubbone, you can only have one size at any given time , though you can redim it to fit more or less elements. However, if you absolutely need to have varying dimensions, you can put arrays inside an array, though you have to ask yourself if its worth it or if you can think of a better way.

Share this post

Link to post
Share on other sites

Thanks to all. Well, the redim may be what i was looking for. Don't worry about all the syntax errors, I know them and by the way the error check won't let me run the script if there are any :mellow: It was just to make the situation more clear.

Anyway, I need that 2d array because of this function (which I still need to work because it's not working properly):

#include <array.au3>
Func ColloquioDomande()
    Local $Domande[5]=["doma","domb","domc","domd","dome"]
    Local $Risposte[20]=["a","b","c","d","a1","b1","c1","d1","a2","b2","c2","d2","a3","b3","c3","d3","a4","b4","c4","d4"]
    Local $DomandeDifferenti[4]
    Local $RisposteMischiate[4]
    For $z=1 to 4
        Local $GiroDomande=Random(1,Ubound($Domande)-1,1)
            Case $GiroDomande=0
                Local $Risp1=$Risposte[0],$Risp2=$Risposte[1],$Risp3=$Risposte[2],$Risp4=$Risposte[3]
            Case $GiroDomande=1
                Local $Risp1=$Risposte[4],$Risp2=$Risposte[5],$Risp3=$Risposte[6],$Risp4=$Risposte[7]
            Case $GiroDomande=2
                Local $Risp1=$Risposte[8],$Risp2=$Risposte[9],$Risp3=$Risposte[10],$Risp4=$Risposte[11]
            Case $GiroDomande=3
                Local $Risp1=$Risposte[12],$Risp2=$Risposte[13],$Risp3=$Risposte[14],$Risp4=$Risposte[15]
            Case $GiroDomande=4
                Local $Risp1=$Risposte[16],$Risp2=$Risposte[17],$Risp3=$Risposte[18],$Risp4=$Risposte[19]
        Local $RisposteInOrdine[4]=[$Risp1,$Risp2,$Risp3,$Risp4]
        For $i=1 to 4
            Local $GiroRispInOrdine=Random(1,Ubound($RisposteInOrdine)-1,1)
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    Return $MultiDomERisp

Quick Explanation: This program should extract from 2 arrays given a question and 4 answers for each question, always checking that the previous question and answer have not been already extracted amd, to scramble the answers everytime to put them in a different order. Questions are $Domande and answers are $Risposte. The results are given into 2 arrays which, as far as i know, cannot be returned with a single Return

at the end of the functionm therefore i have to store them in a multidimensional array and make a return whichi gives the multidimensional array as result of the function.

That's why i need it. But if you know a better solution i'm all ears.

Thanks :P

Edited by niubbone

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...