472,989 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

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 25926
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
1
by: Jack Addington | last post by:
I have a 3rd party object that fires an itemchanged event when someone edits some data on a form. This event has a custom eventArgs that has a field called ActionCode. In the code of the event,...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
43
by: Tim Chase | last post by:
Just as a pedantic exercise to try and understand Python a bit better, I decided to try to make a generator or class that would allow me to unpack an arbitrary number of calculatible values. In...
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
80
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.