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. 14 1902
* "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/>
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
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
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
* 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/>
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
* "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/>
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
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
* "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/>
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
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.
"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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: v4vijayakumar |
last post by:
Why we need "virtual private member functions"? Why it is not an
(compile time) error?
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |