Skip to main content

Ref

Ref (Função)​

Formato​

subroutine nome_da_subrotina ( ref(variável),variável )
call nome_da_subrotina ( ref(variável),variável )

function nome_da_função ( ref(variável),variável )
nome_da_função ( ref(variável),variável )

devolve expressão_inteira

Descrição​

Por predefinição, os valores são passados às Subroutines e Functions por valor. Isto quer dizer que o valor indicado ao chamar a rotina é copiado para uma variável que pertence à rotina e é totalmente local a ela.
A declaração ref() permite passar à rotina uma referência a uma variável ou a um array. Quando a rotina muda o valor de uma variável referenciada, a mudança é feita na variável original usada na chamada da rotina.

Exemplo​

dim a(10)
call assignarray(ref(a),10)
print "total="+totalarray(ref(a),10)
end

subroutine assignarray(ref(array), arraylen)
# atribuir os elementos do array
for t = 0 to arraylen-1
array[t]= t*t
print array[t]
next t
end subroutine

function totalarray(ref(array),arraylen)
totalarray = 0
for t = 0 to arraylen-1
totalarray += array[t]
next t
end function

mostra

0
1
4
9
16
25
36
49
64
81
total=285

Ver também​

Begin Case / Case / End Case, Call, Continue Do, Continue For, Continue While, Do / Until, End, Exit Do, Exit For, Exit While, For / Next, For Each / Next, Function, Global, Goto, Gosub, If Then, Pause, Ref, Rem, Return, Subroutine, While / End While

Histórico​

0.9.9.13Novo nesta versão