Sub return
Posted: 02 June 2009, 5:49 AM
Hello!
I'm new to ZBasic and I stumbled into some difficulties. How do I make my subs return a value? Can I return an array? I tried with the command return (as in java), but got error.
This is what I'd like:
The commented parts doesn't work.
I know that functions return values, but I haven't been able to return arrays.
My application is actually a simple genetic algorithm to calculate function maximum/minimum. I can post it when I'm done.
I'm new to ZBasic and I stumbled into some difficulties. How do I make my subs return a value? Can I return an array? I tried with the command return (as in java), but got error.
This is what I'd like:
Code: Select all
Dim a(1 to 5) as Bit
Dim b(1 to 5) as Bit
Dim c(1 to 5) as Bit
Dim i as Byte = 1
For i = 1 to 5
a(i) = CBit(CInt(Fix(Rnd())))
b(i) = CBit(CInt(Fix(Rnd())))
Next i
' c(1 to 5) = big(a, b)
i = 1
For i = 1 to 5
Console.Write(CStr(c(i)))
Next i
Sub big(ByRef a() as Bit, ByRef b() as Bit)
Dim c(1 to 5) as Bit
Dim i as Byte = 1
For i = 1 to 5
If a(i) < b(i) Then
c(i) = b(i)
Else
c(i) = a(i)
End If
Next i
' Return c
End Sub
I know that functions return values, but I haven't been able to return arrays.
My application is actually a simple genetic algorithm to calculate function maximum/minimum. I can post it when I'm done.