Why we give a function data type?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why we give a function data type?
when we declare a function we gave a name and datatype for that function what for?
if i make a parameter i declare it and give it a datatype and if i use variabels in function i daclare it too so what the use of datatype function??
 
The Basic Defintion of a funtion is a method that returns data. They is why
you give them a type. Usally you process some information in the Function
and the function returns it's result.

vb. said:
Why we give a function data type?
when we declare a function we gave a name and datatype for that function what for?
if i make a parameter i declare it and give it a datatype and if i use
variabels in function i daclare it too so what the use of datatype
function??
 
vb. said:
Why we give a function data type?
when we declare a function we gave a name and datatype for that function what for?
if i make a parameter i declare it and give it a datatype and if i use
variabels in function i daclare it too so what the use of datatype
function??

To prevent that you accidentally returning the wrong datatype (use 'Object'
if you need a Function that can return multiple datatypes)?

When you give a function in a Class a DataType, Code outside the Class that
calls the Function, can see What Datatype to expect in return from that
Function.

I guess that the Compiler could look at the code inside your Function and
see what DataType the Variable that returns a value got, but there might be
several
return-statements in a function. Witch one would be the correct one, and it
would require the Compiler to scan through you code ever time you made a
referance to a function, making it very inefficient and slow.
 
Sometimes you need to return a new reference to an object. Or return a
reference to a new object.

Regards - OHM
 
Seams you are new in developping with VB and coming from C++......

In VB there are SUB's and Functions in C there are only functions.

If your Function don't has a Returnvalue then you can use "SUB " instead of
a "FUNCTION"

A Function only makes sense if it returns something......



vb. said:
Why we give a function data type?
when we declare a function we gave a name and datatype for that function what for?
if i make a parameter i declare it and give it a datatype and if i use
variabels in function i daclare it too so what the use of datatype
function??
 
Hi VB

The function is no datatype, you tell what you want to give back.

But while I am writting this down I think also that it is a little bit old
fashion because that you can see in the function.

Something from the old teletype time and before to see if what is typed in
is correct.

Cor
 
* =?Utf-8?B?dmIu?= said:
Why we give a function data type?

The return value? To return a value in a specific type. For example a
string or an integer.
when we declare a function we gave a name and datatype for that
function what for?

You have a name too. And a "function" too. What for?

The name is used for identification within your code, the datatype is
used to tell the user/code which datatype the returned value has.
if i make a parameter i declare it and give it a datatype and if i use
variabels in function i daclare it too so what the use of datatype
function??

....
 
Back
Top