I'm using #lang "fb".
Me again. Do functions need to be defined to return a certain data type? Like this:
Function foo(a as integer) as integer
If my function does not have a data type, will it be defined as the default data type?
What is the default data type in FB?
Thanks again.
FUNCTIONS need a type to return?
-
- Posts: 306
- Joined: Jun 02, 2005 7:11
- Contact:
There are two method types subs and functions, functions return a value, subs don't. Both accept parameters.
I don't know what you mean by default data type.
Code: Select all
declare sub MethodA(value as integer)
declare function MethodB(value as integer) as integer
Try it, the answer is in the error message.
error 136: Default types or suffixes are only valid in -lang deprecated or fblite or qb in 'function xxx()'
Code: Select all
function xxx()
end function
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
In lang FB, you have to put AS INTEGER or AS STRING after the final ) of the function.
FreeBasic is pretty strict, about wanting to know what you wanna do with your data.
I call it, the most Turbo Pascal'ish version of BASIC out yet.
You have to declare every single variable, and you have to declare exactly what data types you wanna use.
:.:
When you try to leave a function, like so..
FUNCTION LLAMACOOKIE(inputllama as integer)
and don't put this..
FUNCTION LLAMACOOKIE(inputllama as integer) as STRING
then FB thinks you wanna go back to Qbasic-like syntax.
If you're purposely using lang FB, then you must apply yourself to use the strict coding methods of FB.
Every FUNCTION must have a particular TYPE of variable, it is supposed to return.
Even a function with no particular input variable.
FUNCTION SOMETHINGCUTE() as string
See how it has opening and closing parenthasissietes.. but it too, has an AS SOMETHING, telling it, that you want it to be SOMETHING.
~Kiyote!
Yes, to get it to work in lang FB, you must put as AS STRING, AS INTEGER, AS LONG, AS LONGINT, AS UBYTE, whatever you want, just something.
FreeBasic is pretty strict, about wanting to know what you wanna do with your data.
I call it, the most Turbo Pascal'ish version of BASIC out yet.
You have to declare every single variable, and you have to declare exactly what data types you wanna use.
:.:
When you try to leave a function, like so..
FUNCTION LLAMACOOKIE(inputllama as integer)
and don't put this..
FUNCTION LLAMACOOKIE(inputllama as integer) as STRING
then FB thinks you wanna go back to Qbasic-like syntax.
If you're purposely using lang FB, then you must apply yourself to use the strict coding methods of FB.
Every FUNCTION must have a particular TYPE of variable, it is supposed to return.
Even a function with no particular input variable.
FUNCTION SOMETHINGCUTE() as string
See how it has opening and closing parenthasissietes.. but it too, has an AS SOMETHING, telling it, that you want it to be SOMETHING.
~Kiyote!
Yes, to get it to work in lang FB, you must put as AS STRING, AS INTEGER, AS LONG, AS LONGINT, AS UBYTE, whatever you want, just something.
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
In QBasic, the default type, was whatever you did like so.
DEFINT A-Z
That mean't, that each of those randomly created variables you made, should automatically, without a doubt, be integers.
In FreeBasic, lang FB, there is no default data type.
You must say so, for each routine, and each variable.
A huge ain n he ss, I know.
But, it teaches you better coding methods.
It shows you, just how many variables you actually use.
~Kiyote!
I use generic names for some variables.
DIM REUSABLE AS INTEGER
DIM WOLFCODE1 AS STRING, WOLFCODE2 AS INTEGER
DIM LLAMACODE1 AS INTEGER
DEFINT A-Z
That mean't, that each of those randomly created variables you made, should automatically, without a doubt, be integers.
In FreeBasic, lang FB, there is no default data type.
You must say so, for each routine, and each variable.
A huge ain n he ss, I know.
But, it teaches you better coding methods.
It shows you, just how many variables you actually use.
~Kiyote!
I use generic names for some variables.
DIM REUSABLE AS INTEGER
DIM WOLFCODE1 AS STRING, WOLFCODE2 AS INTEGER
DIM LLAMACODE1 AS INTEGER
-
- Posts: 1009
- Joined: Oct 11, 2008 7:42
- Location: ABQ, NM
- Contact:
Code: Select all
declare function blink() as integer
function blink() as integer
static blinkvalue as integer
blinkvalue = 1 - blinkvalue
blink = blinkvalue
end function
Code: Select all
declare function blink() as integer
function blink() as integer
static blinkvalue as integer
blinkvalue = 1 - blinkvalue
return blinkvalue
print "This PRINT statement will not be executed."
end function
The return command does two things.
One, it passes on the final answer of the routine, and also, it terminates the routine, the same as EXIT FUNCTION does.
If you wish to modify your return value often, then use a dummy variable, then assign the final return value at the very end.
~Kiyote![/code]