468,490 Members | 2,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

Sub - return values

Every other language I've worked in, you can return a value from a
subroutine/method/function.
Unless I've missed something basic (no pun intended) you can't do that in
VB.NET

AFAICS I can do it in C#, but not in VB, am I right?
--

PAul
Nov 20 '05 #1
13 25045
Hi,

You can return values with vb.net. You can change a variable passed
byref, and of course functions return values. Here are some simple examples.

Private Function ReturnPi() As Double

Return 3.14

End Function

Private Sub ChangeX(ByRef x As Integer)

x = x + 3

End Sub
Ken
---------------------
"PAul Maskens" <pm******@mvps.org> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
Every other language I've worked in, you can return a value from a
subroutine/method/function.
Unless I've missed something basic (no pun intended) you can't do that in
VB.NET

AFAICS I can do it in C#, but not in VB, am I right?
--

PAul

Nov 20 '05 #2
"PAul Maskens" <pm******@mvps.org> schrieb
Every other language I've worked in, you can return a value from a
subroutine/method/function.
Unless I've missed something basic (no pun intended) you can't do
that in VB.NET

AFAICS I can do it in C#, but not in VB, am I right?

public function test() as integer
return 17
end function

http://msdn.microsoft.com/library/en...Procedures.asp
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Cor
Hi Paul,

No you are wrong.

In VB you have Subs without return values and the same as in other language
Functions with return values.

I hope this was what you where looking for?

Cor
Nov 20 '05 #4
Thanks all.

SUB - can't return a value
FUNCTION - can return a value

Simple!

The designers always seem to emit Sub/End Sub which led me down the blind
alley.
Nov 20 '05 #5
* "PAul Maskens" <pm******@mvps.org> scripsit:
Every other language I've worked in, you can return a value from a
subroutine/method/function.
Unless I've missed something basic (no pun intended) you can't do that in
VB.NET


\\\
Public Function Foo() As Integer
Return 1
End Function
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

"PAul Maskens" <pm******@mvps.org> wrote in message
news:uK**************@TK2MSFTNGP09.phx.gbl...
Every other language I've worked in, you can return a value from a
subroutine/method/function.


Oh the joys of terminological confusion:

"subroutine"

VB calls this a Sub and you /cannot/ return a result from one.
Sub Fred
' lots of good stuff
End Sub

"function"

VB calls this (surprise, surprise) a Function and you can return
results from them (and, IIRC, Option Strict On insists on it).

Function Foo( ... ) as <<ReturnDataType>>
Foo = <<value>>
' or
Return <<value>>
' or both
End Function

Property (the one you're missing)

This frequently exposes variables within a class to the "Outside
World". You assign values to them and read their value back
just like any other variable.

Public Property Thing() As <<DataType>>
Get
Return <<value>>
End Get
Set(ByVal Value As Integer)
<<variable>> = value
End Set
End Property

"method"

This one's the grey area because it depends entirely on how /you/
define them - a "method" can be either a Sub or a Function, as per
the "rules" above.

HTH,
Phill W.
Nov 20 '05 #7
Cor
Hi Herfried,
\\\
Public Function Foo() As Integer
Return "1"
End Function
///


Is this your version to show that 1+1 is not 2?
\\\
Message = Foo+Foo
///

:-))

Cor

Nov 20 '05 #8
Cor,

* "Cor" <no*@non.com> scripsit:
\\\
Public Function Foo() As Integer
Return "1"
Why did you add the quotes around 1?
End Function
///


Is this your version to show that 1+1 is not 2?
\\\
Message = Foo+Foo
///


?!?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
"Cor" <no*@non.com> schrieb
\\\
Public Function Foo() As Integer
Return "1"
End Function
///


Where do the " in your quote come from?
--
Armin

Nov 20 '05 #10
Cor
Hi Herfried,

Stupid me, I was sending a message to you totaly different but it was not
good for a mail message only for a face to face message (could be
misunderstood) , changed it, and than I left the quotes.

:-))

But it is a nice method to show that 1+1=11

:-))

Cor
Nov 20 '05 #11
Cor
> >
\\\
Public Function Foo() As Integer
Return "1"
End Function
///


Where do the " in your quote come from?


I know that will not even compile with option strict on

Put always option Strict On in top of your program

:-))

Cor
Nov 20 '05 #12
* "Cor" <no*@non.com> scripsit:
Stupid me, I was sending a message to you totaly different but it was not
good for a mail message only for a face to face message (could be
misunderstood) , changed it, and than I left the quotes.

:-))

But it is a nice method to show that 1+1=11


:-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #13
"Cor" <no*@non.com> schrieb

> \\\
> Public Function Foo() As Integer
> Return "1"
> End Function
> ///


Where do the " in your quote come from?


I know that will not even compile with option strict on

Put always option Strict On in top of your program

:-))


I wanted to know where they came from.
--
Armin

Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

66 posts views Thread by Darren Dale | last post: by
1 post views Thread by Jack Addington | last post: by
5 posts views Thread by Edward Diener | last post: by
16 posts views Thread by Nikolay Petrov | last post: by
43 posts views Thread by Tim Chase | last post: by
8 posts views Thread by aleksandar.ristovski | last post: by
80 posts views Thread by xicloid | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.