473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Functions

I know how to call a finction and pass a parameter to it, but I don;t
understand how to take the resulting output of the function and use it from
the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original subroutine.
Nov 20 '05 #1
14 1893
* "Microsoft" <ma*@mas.com> scripsit:
I know how to call a finction and pass a parameter to it, but I don;t
understand how to take the resulting output of the function and use it from
the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original subroutine.


\\\
Public Function DivideBy2(ByVal Number As Double) As Double
Return Number / 2
End Function
..
..
..
Dim d As Double = DivideBy2(34.56)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Microsoft wrote:
I know how to call a finction and pass a parameter to it, but I don;t
understand how to take the resulting output of the function and use it from
the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original subroutine.


Sub test1
Dim i as Integer = 2
Dim f as Float = test2(i)
'Now f has the result of function test2
End Sub

Funktion test2(ByVal i as Integer)
Dim f as Float = i / 2
Return f
End Funktion

Cheers

Arne Janning
Nov 20 '05 #3
Arne Janning wrote:
Microsoft wrote:
I know how to call a finction and pass a parameter to it, but I don;t
understand how to take the resulting output of the function and use it
from
the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original subroutine.

Sub test1
Dim i as Integer = 2
Dim f as Float = test2(i)
'Now f has the result of function test2
End Sub

Funktion test2(ByVal i as Integer)
Dim f as Float = i / 2
Return f
End Funktion

Cheers

Arne Janning


Ups,

this won't work...

Sub test1
Dim i as Integer = 2
Dim f as Float = test2(i)
'Now f has the result of function test2
End Sub

Funktion test2(ByVal i as Integer) as Float
Dim f as Float = i / 2
Return f
End Funktion

Now it works ;-)
Or take Herfrieds version...

Cheers

Arne Janning
Nov 20 '05 #4
Thanks for the replies. Can a fumction return more than one value in vb.net?
"Arne Janning" <sp*****************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Microsoft wrote:
I know how to call a finction and pass a parameter to it, but I don;t
understand how to take the resulting output of the function and use it from the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original
subroutine.
Sub test1
Dim i as Integer = 2
Dim f as Float = test2(i)
'Now f has the result of function test2
End Sub

Funktion test2(ByVal i as Integer)
Dim f as Float = i / 2
Return f
End Funktion

Cheers

Arne Janning

Nov 20 '05 #5
"Microsoft" <ma*@mas.com> schrieb
I know how to call a finction and pass a parameter to it, but I
don;t understand how to take the resulting output of the function and
use it from the subroutine that called the function

Something like

I have a number
I send the number to a fumction that divides it by 2
I then can refer to the quotient as a variable in my original
subroutine.


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 #6
* Arne Janning <sp*****************@msn.com> scripsit:
Dim f as Float = test2(i)
'Float'?
Funktion test2(ByVal i as Integer) as Float
Dim f as Float = i / 2
Return f
End Funktion
'Funktion'?
Now it works ;-)
Or take Herfrieds version...


LOL!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
Microsoft wrote:
Thanks for the replies. Can a fumction return more than one value in vb.net?


No. (See the link posted by Armin)

But it can return arrays, structures or objects which can of cource
contain more than one value.

Cheers

Arne Janning
Nov 20 '05 #8
* "Microsoft" <ma*@mas.com> scripsit:
Thanks for the replies. Can a fumction return more than one value in vb.net?


There are different ways to return more than one value:

\\\
Public Sub Swap(ByRef x As Integer, ByRef y As Integer)
dim t As Integer = x
x = y
y = t
End Sub
..
..
..
Dim i As Integer = 22
Dim j As Integer = 99
Swap(i, j)
MsgBox(CStr(i))
MsgBox(CStr(j))
///

- or -

\\\
Public Class CalculationResult
Public x As Integer
Public y As Integer
Public s As String
...
End Class
..
..
..
Public Function Calculate(...) As CalculationResult
Dim c As New CalculationResult()
c.x = ...
c.y = ...
Return c
End Function
..
..
..
Dim c As CalculationResult = Calculate(...)
MsgBox(CStr(c.x))
MsgBox(CStr(c.y))
MsgBox(c.s)
///

- or -

\\\
Public Function Foo() As String()
Return New String() {"Hello", "World"}
End Function
..
..
..
Dim astr() As String = Foo()
MsgBox(astr(0))
MsgBox(astr(1))
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
Herfried K. Wagner [MVP] wrote:
* Arne Janning <sp*****************@msn.com> scripsit:
Dim f as Float = test2(i)

'Float'?

Funktion test2(ByVal i as Integer) as Float
Dim f as Float = i / 2
Return f
End Funktion

'Funktion'?

Now it works ;-)
Or take Herfrieds version...

LOL!


OK Herfried,

let's take your version.
Seems like I won't be able to get this working ;-)

Cheers

Arne Janning
Nov 20 '05 #10
Hi Arne,

From which country are you, Herfried saw the same as me, "Funktion" while it
is normaly in the program languages Function.

That was the only LOL about it, I think you made consequent typos by typing
it in the message.

(It is not impossible it is in the German language with a K, I do not know
that, in Dutch it is official with C however often written with a K)

:-)

Cor
Nov 20 '05 #11
* "Cor Ligthert" <no**********@planet.nl> scripsit:
From which country are you, Herfried saw the same as me, "Funktion" while it
is normaly in the program languages Function.

That was the only LOL about it, I think you made consequent typos by typing
it in the message.

(It is not impossible it is in the German language with a K, I do not know
that, in Dutch it is official with C however often written with a K)


AFAIK, Arne is from Germany, and in German it's "Funktion". I assume
Arne uses C# more than he uses VB.NET, so he doesn't know how to spell
'Function' :-).

SCNR

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12
Herfried K. Wagner [MVP] wrote:
* "Cor Ligthert" <no**********@planet.nl> scripsit:
From which country are you, Herfried saw the same as me, "Funktion" while it
is normaly in the program languages Function.

That was the only LOL about it, I think you made consequent typos by typing
it in the message.

(It is not impossible it is in the German language with a K, I do not know
that, in Dutch it is official with C however often written with a K)

AFAIK, Arne is from Germany,


Correct.

and in German it's "Funktion". I assume Arne uses C# more than he uses VB.NET,
Correct as well, although I have been a VB-Classic-programmer for years.

so he doesn't know how to spell 'Function' :-).


I only spent too much time in writing a custom wrapper class for the
IActiveDesktop interface and did the post without concentration :-(

I'm sorry for that.

Cheers

Arne Janning

Nov 20 '05 #13
Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the same
name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena's Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....
No mention of index being an array as Dim index As Array

Sum? Is that a keyword being used, or just a poor choice of a symbol
representation?
So far, I'm getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I'm not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

Dennis D.
Nov 21 '05 #14
"Dennis D." <te**@dennisys.com> wrote in message
news:uj**************@TK2MSFTNGP09.phx.gbl...
Hello:

I want a function to return three variables to the calling procedure:

Private Function CalcTimes(ByVal iAddDays as Integer, ByVal iAddHours as
Integer, ByVal iAddMins as Integer) As Array

Variable values are calculated in the function.

Calling procedure receives the values preferably into variables of the
same name.

Like: Me.CalcTimes(iAddDays, iAddHours, iAddMins)

Further use is ...(New TimeSpan(iAddDays, iAddHours, iAddMins, 0))

Could use ParamArray Arguments?

Is As Array correct or should it be As Integer?
Do I need to declare CalcTimes as an array before it is used, or is it an
array by definition?

This is somewhat confusing to me.
Balena's Prog-Vb ParamArray example begins:
Function Sum(ParamArray ByVal args() As Integer) As Integer
Dim index As Integer
For index = 0 to UBound(args)....
No mention of index being an array as Dim index As Array

Sum? Is that a keyword being used, or just a poor choice of a symbol
representation?
So far, I'm getting a debug error. I tried a return statement:
Return CalcTimes(iAddDays, iAddHours, iAddMins)
I'm not even sure about using a return statement here. It immediately
preceeds the End Function statement anyway.
Sorry about being lazy. 5:36AM is near end of the day for me.
Thanks.

Dennis D.

Whoops. Index is a counter. My bass.
Nov 21 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.