Hey everyone,
I'm just practising writing functions, but I'm still stumbling at passing values to and from them. If I can, I'd like to avoid declaring variables as global just to get them working with functions. Have a look at my code below;
Rem Project: Function Test
Rem Created: Monday, May 24, 2010
Rem ***** Main Source File *****
Global Test As String
Do
Userinput()
Systemprocess()
Systemoutput()
LOOP
Function Userinput()
input "Please type in a colour; red, blue or green: ", Test
Endfunction
Function Systemprocess()
Select Test
Case "exit"
CLS
Print "Have a great day!"
Wait key
End
EndCase
Case "red", "Red", "RED"
INK RGB(128,0,0), RGB(255,87,87)
EndCase
Case "blue", "Blue", "BLUE"
INK RGB(0,0,128), RGB(160,192,255)
EndCase
Case "green", "Green", "GREEN"
INK RGB(0,128,82), RGB(161,255,160)
EndCase
Case default
CLS
Print "Try type in either red, green or blue."
Test = "white"
INK RGB(255,255,255), RGB(0,0,0)
Wait key
EndCase
EndSelect
EndFunction
Function Systemoutput()
cls
Print "Function Test"
Print "Text has been changed to ", Test
ENDFUNCTION
If you can assist me in tidying up this example, I'd be most great full.
Here's another example, it only works if I declare y$ as global.
Do
Input "Please enter the word 'test': " , userinput$
afunc(userinput$)
Print "Out of function, results: ", afunc(functionoutput$)
Wait key
cls
LOOP
Function afunc(functionarguement$)
Print "You entered ", functionarguement$
functionoutput$ = "Successfull"
Print "Inside function, test Results: ", functionoutput$
wait key
ENDFUNCTION functionoutput$
At the "Endfunction" line, I think I've seen examples where programmers put a return value, like "Endfunction y$" but I don't quite understand this either...
Cheers in advance,
BFM
EDIT: Tidied up my example a bit.