Sub - return values

  • Thread starter Thread starter PAul Maskens
  • Start date Start date
P

PAul Maskens

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 Maskens said:
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-us/vbcn7/html/vbconFunctionProcedures.asp


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
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
 
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
 
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.
 
* "PAul Maskens said:
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
///
 
PAul Maskens said:
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.
 
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
 
* "Cor said:
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 said:
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.
 
Back
Top