[Gambas-user] Variable ByVal

Leonardo Miliani leonardo at ...1237...
Fri Nov 25 14:57:18 CET 2005


I wrote a little program that utilizies some sorting algorithms to order 
a test array.
But I have a problem. I call the sorting algorithm which is included in 
a sub and I pass the array to order using another array. But, after I 
called the sub I get both arrays ordered... Why?
Or, is there a method to pass variables BYVAL, as in Visual Basic?

To understand my problem, here is a little sample:

Public Sub Ordina()
DIM Matrice AS String[0]
DIM Matrice2 AS String[0]

matrice.Resize(elementi)
matrice2.Resize(elementi)
.....
.filling matrice[]
.....
matrice2 = matrice
bubblesort(matrice2)
....
..here I get both matrice and matrice2 ordered!
....
Enf

Public sub bubblesort(matrix as string[])
DIM I AS Integer
DIM J AS Integer
DIM X AS String

    FOR I = 2 TO elementi
       FOR J = elementi TO I STEP -1
          IF matrix[J - 1] > matrix[J] THEN
             X = matrix[J - 1]
             matrix[J - 1] = matrix[J]
             matrix[J] = X
          END IF
       NEXT
    NEXT
END

It is very strange for me, because all the operations are made on 
matrix[], which gets its datas from matrice2[], not directly from matrice[].


-- 
Ciao.
Leo

Visita il mio sito personale: www.leonardomiliani.com
e-mail: leonardo at ...1237...




More information about the User mailing list