[Gambas-user] Questions about function

Leonardo Miliani leonardo at ...1237...
Fri Sep 29 22:41:12 CEST 2006


wspinto at ...1405... ha scritto:
> Hi!
> 
> In VB the functions and Sub use MYSUBFUNCTION([ByRef | ByVal] myVariable as
> typeofvariable) as typeofreturn
> 
> Example:
> SUB MYSub1(b as integer)
>     b = b ^ 2
> END SUB
> 
> SUB MYSub2(ByRef b as integer)
>     b = b ^ 2
> END SUB
> 
> a = 10
> PRINT a <== Return 10
> MYSub1(a)
> PRINT a <== Return 10
> MySub2(a)
> PRINT a <== Return 100
> 
> Well! My problem...
> 
> I'm have one variable named oTabIndex is Object[] and fill with this function
> 
> PUBLIC FUNCTION MakeTabIndex(oForm AS Form) AS Object[]
>   DIM sClass AS Object
>   DIM cRetorno AS NEW Object[]
> 
>   FOR EACH sClass IN oForm.Controls
>     IF sClass Is TEXTBOX or sClass Is COMBOBOX or sClass Is CHECKBOX or sClass
> Is LISTBOX
>         THEN  cRetorno.Add(sClass)
>   NEXT
> 
>   RETURN cRetorno
> END
> 
> PUBLIC SUB Form_Open()
>     oTabIndex = mymodule.MakeTabIndex(ME)
> END
> 
> PUBLIC SUB loc_KeyPress()    '* loc is group of my form objects
>     If Key.Code = Key.Enter or Key.Code = Key.Return then
>         FtabIndex(oTabIndex,LAST,0)
>     End If
> END
> 
> FUNCTION FTabIndex(oTabIndex AS Object[], oCampo AS Object, OPTIONAL nOrdem AS
> Integer = 0) AS Boolean
>     DIM nConta AS Integer
>     DIM i AS Integer
> 
>     i = oTabIndex.Count - 1
>     nConta = oTabIndex.Find(oCampo)
>     IF nConta < 0 THEN RETURN FALSE
> 
>     IF nOrdem = 0 THEN
>         ' Verifica se o campo esta enable ou nao visible
>         nConta += 1
>         IF nConta = i THEN nConta = 0
>         WHILE NOT oTabIndex[nConta].enabled OR NOT oTabIndex[nConta].visible
>             nConta += 1
>             IF nConta = i THEN nConta = 0
>         WEND
>     ELSE
>         nConta -= 1
>         IF nConta <= 0 THEN nConta = i
>         WHILE NOT oTabIndex[nConta].enabled OR NOT oTabIndex[nConta].visible
>             nConta -= 1
>             IF nConta <= 0 THEN nConta = i
>         WEND
>     ENDIF
> 
>     oTabIndex[nConta].SetFocus
>     RETURN TRUE
> END
> 
> **************
> In any moment the oTabIndex itens not exist
> example:
> For i = 0 to oTabIndex.Count - 1
>     Print oTabIndex[i].Tag
> Next
> 
> first time the work fine. In second time in i = 5 the oTabIndex[5].Tag is
> invalid or any other: .Text, .X, etc...
> 
> Why?????????
> 
> 
> Reguards,
> 
>      Wellington
> ___________________________________________________________________________________
> Agora todas as suas ligações DDD e DDI com o 21 vêm junto com a conta do seu
> telefone de casa ou celular. 
> Mais comodidade e praticidade para você. Faz um 21 e aproveite!
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> 

I know that in Gambas a variable passed to a function/sub is used as
"Byval" in VB. Instead, a dinamic array (variable[]) is used as "Byref"
in VB, so if you change its value then the calling sub will see the new
value.

-- 
Ciao.
Leo.

Web: www.leonardomiliani.com
E-mail: leonardo at ...1237...
Scegli software opensource - Choose opensource software





More information about the User mailing list