Hi, i use ubuntu 9.10 and Gambas 2.13
i create an anagram application port from phpAG http://phpag.sourceforge.net/ i completed the same app with VB5 and now i make it also in Gmabas To make anagrams i use recursion i face up with a problem of recursion. i call anag() function from PUBLIC SUB Button1_Click() .... anag(0, iLen, sArray) 'Make anagrams .... END And the function is this PRIVATE FUNCTION anag(iStart AS Integer, iLen AS Integer, sArray AS Array) 'vars are ByVal by default 'Port code from phpAG code ' / * FOR ($j = $start; $j < $len; + + $j) ' { ' IF ($j == $start || $array[$j] != $array[$start]) ' { ' $tmp = $array[$j]; ' $array[$j] = $array[$start]; ' $array[$start] = $tmp; ' anag($array, $start + 1, $len); ' } ' } ' * / DIM j AS Integer DIM tmp AS String DIM word AS String IF iStart < iLen THEN j = iStart WHILE (j < iLen) IF (j = iStart OR sArray[j] <> sArray[iStart]) THEN tmp = sArray[j] sArray[j] = sArray[iStart] sArray[iStart] = tmp anag((iStart + 1), iLen, sArray) 'recursion does not work properly END IF j = j + 1 WEND ELSE word = implode(sArray) TextArea1.Text = TextArea1.Text & word & gb.NewLine 'Vb5 PRINT #2, word 'write to anagram.tmp the result ' END IF END PRIVATE FUNCTION implode(sArray AS Array) AS String 'This function makes a string from the elements of a string array DIM i AS Integer DIM word AS String FOR i = 0 TO (sArray.Length - 1) word = word & sArray[i] NEXT RETURN word END --------------- So if user enter the letters "abc" must have all the combinations as abc acb cab cba bca bac The same code works for vb5 like this Private Function anag(ByVal iStart As Integer, ByVal iLen As Integer, ByVal sArray As Variant) 'Port code from phpAG If iStart < iLen Then j = iStart While (j < iLen) If j = iStart Or sArray(j) <> sArray(iStart) Then tmp = sArray(j) sArray(j) = sArray(iStart) sArray(iStart) = tmp Call anag((iStart + 1), iLen, sArray) End If j = j + 1 Wend Else word = implode(sArray) Text2.Text = Text2.Text & word & vbNewLine Print #2, word 'write to anagram.tmp the result End If End Function in Gambas i get wrong results i get abc acb cab cba abc acb This means recursion does not work properly. In VB5 it was needed to pass values BYVAL i read that this is the defaut in Gambas. But does not work. Why? i attach my program for whoever want to help. -- Γεια χαρα σε όλους!!! Regards, Demosthenes Koptsis
Anagramatismos.tar.gz
Description: GNU Zip compressed data
------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________ Gambas-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gambas-user
