-
October 24th, 2009, 07:14 AM
#1
functino that returns nothing
hi, is there anyway to make a proper function that does not return anything. when i try to create i get this kind of error:
A null reference exception could occur at run time when the result is used.
when i put as integer behind it gets rid of the error, but i was wondering if there was anyway that i could do to get rid of this thing
-
October 24th, 2009, 09:05 AM
#2
Re: functino that returns nothing
By creating a sub...
Good Luck
-
October 24th, 2009, 10:38 AM
#3
Re: functino that returns nothing
oo, ok sry now it looks real dumb, but vb is really a different dialect, i've yet to come across such a specific language lol
-
October 24th, 2009, 12:15 PM
#4
Re: functino that returns nothing
Post some of your code, and we will try to see what you are trying to do.
-
October 26th, 2009, 08:01 AM
#5
Re: functino that returns nothing
A proper function, as you put it, should return something.
A proper Sub, returns nothing...
-
October 26th, 2009, 08:47 AM
#6
Re: functino that returns nothing
The way VB treats that is quite versatile in fact.
You will write a Sub if you want to use it like a command.
(In Pascal it's called a procedure, so it is not so specific at all).
You write a function if you want to use it within an expression. There it will result in a value anyway when the expression is evaluated.
If your function code does not provide a return value explicitly, zero, or null, or Nothing or Empty is returned depending on the function's data type.
Nevertheless, having a return value or not, any function can be used and treated syntactically like a sub when the return value is not needed.
-
October 26th, 2009, 08:49 AM
#7
Re: functino that returns nothing
Originally Posted by HanneSThEGreaT
A proper function, as you put it, should return something.
A proper Sub, returns nothing...
au contraire Monseigneur Great...
ByRef...
If an API call or user created sub changes one or more values that are passed in as arguements then does not that sub return something? And a function, API or otherwise, treated like a sub, does that not return nothing even though it is setup to? (symantics I know...)
-
October 26th, 2009, 09:15 AM
#8
Re: functino that returns nothing
Originally Posted by vb5prgrmr
au contraire Monseigneur Great...
Touche
Originally Posted by vb5prgrmr
ByRef...
Passing variables By Reference means that you are essentailly creating a pointer to that variable, and then change that. Passing object By Value, you are making a "copy" of the adressed variable.
Originally Posted by vb5prgrmr
If an API call or user created sub changes one or more values that are passed in as arguements then does not that sub return something?
No. A sub is just a sequence of statements, to do whatever, it returns nothing. If obviously you have created a sub, and another sub makes use of something changed / created in the previous sub, that is still not a function, although it works like it.
A Function needs some return value as as pointed out by WoF, even if it Null, Empty or Nothing
Originally Posted by vb5prgrmr
And a function, API or otherwise, treated like a sub, does that not return nothing even though it is setup to? (symantics I know...)
Have a look at this very very interesting thread, dealing with API functions and API subs...
http://www.codeguru.com/forum/showth...owindow&page=2
-
October 26th, 2009, 08:35 PM
#9
Re: function that returns nothing
Originally Posted by HanneSThEGreaT
No. A sub is just a sequence of statements, to do whatever, it returns nothing. If obviously you have created a sub, and another sub makes use of something changed / created in the previous sub, that is still not a function, although it works like it.
Exactly my point!
Originally Posted by HanneSThEGreaT
A Function needs some return value as as pointed out by WoF, even if it Null, Empty or Nothing
But if you treat it like a sub when you call it, it then does not return anything and yes I do understand that a function must be declared as returning something but the point is treating it like a sub, it does not return anything...(at least that is what it seems like on the calling end.)
Overall my point was/is to say that it can be confusing for some newbies
Good Luck
-
October 27th, 2009, 12:58 AM
#10
Re: function that returns nothing
-
October 27th, 2009, 11:28 AM
#11
Re: functino that returns nothing
I think our OP has fled the playground. Hope he understood.
Originally Posted by vb5prgrmr
Exactly my point!
... treating it like a sub, it does not return anything...(at least that is what it seems like on the calling end.)
To be even more pedantic you'd have to say, when called like a sub it still creates a return value, but the calling part does simply not use it.
-
October 27th, 2009, 10:17 PM
#12
Re: functino that returns nothing
...or accept it...
-
October 28th, 2009, 12:55 AM
#13
Re: functino that returns nothing
Originally Posted by WoF
I think our OP has fled the playground. Hope he understood.
In that case, he / she is missing a lot of useful information....
-
October 29th, 2009, 09:47 AM
#14
Re: functino that returns nothing
Yes. Have we some more elaborations to add to this topic?
Maybe we should hint on the miracle of the Call statement.
Why do we have it?
We can write FunctionName Param, why would we write Call FunctionName(Param)?
Because we love the brackets?
FunctionName(Param) cannot stand alone. Why?
Because now it produces a value which MUST be used somehow, or so it seems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|