Skip to main content

Return variables to main

Hello, 
I have a question, i have a script with main and functions, so i can't return variable of function to main. It is possible? 
For example:
"MAIN"
......
var_return = Call custom_function1
.....
///////////////////////////////////////////////////////////////////////////////////////////////////
Function custom_function1
.....
....
Return var1
End function
Thank you!

Brian Element Tue, 06/22/2021 - 16:13

Yes it is possible, you need to make the return value equal to the function name.  Also in your call you don't need the call key word.  Here is an example for you:


option explicit

Sub Main
	Dim var_return  As String
	var_return = custom_function1()
	MsgBox var_return
End Sub

Function custom_function1() As String
	'to return a value make it equal to the function name
	custom_function1 = "This is the return value" 
End Function