but gosub is to function as an internal function, and does every fuction have to have an end function or not?
gosub as well as goto is very frowned upon, maybe a lot more than goto
I find it useful in constructions when you have many nested instructions because the editor does not close pieces, but as soon as I remove the gosub
or when you do not want to create a function that will not be useful outside of that macro and besides having multiple calls you have to deal with many variables
as I said so I started vba I did not know what was functions so I used gosub,
in something like this:
For w = 1 To k
'Origem --( Leitura )--
If Op = 0 Then GoSub OCoL: If T = 1 Then T = 0: GoSub OLin
If Op = 1 Then GoSub OLin: If T = 1 Then T = 0: GoSub OCoL
Ddo = Cells(Loi, Coi).Value2
'Destino --(Escrita )--
If Dp = 0 Then GoSub DCoL: If T = 1 Then T = 0: GoSub DLin
If Dp = 1 Then GoSub DLin: If T = 1 Then T = 0: GoSub DCoL
Cells(Ldi, cdi).Value2 = Ddo
Next
''-----------------( Fim do loop )----
GoTo saida
'----------------------------( ORIGEM )------------
OLin:
If Op = 0 Then
...
Else
...
If Oquadante_L = True Then GoSub OCoL:
...
Else
...
If Oquadante_L = True Then GoSub OCoL:
End If
Return
OCoL: '----( Controle de colunas )---
If Op = 0 Then
...
GoSub OLin:
...
Else
...
GoSub OLin:
...
Else
GoSub OLin:
End If
Return
'---------( DESTINO )-----------
DLin:
If Dp = 0 Then
...
GoSub DCoL:
Else
...
If Dquadante_L = True Then GoSub DCoL:
...
Else
...
If Dquadante_L = True Then GoSub DCoL:
...
End If
Return
DCoL:
...
GoSub DLin:
...
Else
GoSub DLin:
End If
Return
and the call of each function should be something like this
Call funOCoL(Op, Loi, OLi, OLf, OqL, Lig, OZigL, Oquadrante_L, Coi, OCi, OCf, OqC, Cig, OZigC, Oquadrante_C, T)
but in general using functions is much more practical