I’m simply not getting a return value as a parameter from a function.
What am I doing wrong?
PriceA = 53
PriceB = 44
Sort PriceA, PriceB
Print "Lowest Price:", PriceA
Sub Sort(BYREF x, BYREF y)
Dim Temp
If x > y Then
Temp = y
y = x
x = Temp
Exit Sub
Else
Temp = x
x = y
y = Temp
End If
End Sub
In BASIC, a Function can return a value, but a Sub can not.
Simple variables, such as strings and numbers, are passed by value. Complex variables, such as arrays and objects, are passed by reference.
BYREF is not supported.
Here is the correct code:
PriceA = 53
PriceB = 44
Print "Lowest Price:", mySort(PriceA, PriceB)
Function mySort(x, y)
If x < y Then
mySort = x
Else
mySort = y
End If
End Function
I also changed the name of the function from Sort to mySort to lessen confusion: there is also a built in function named sort.
(Note that corrections have been made to the docs in the Wiki - they were misleading)