473,569 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1928
* "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******** ********@tk2msf tngp13.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 CalculationResu lt
Public x As Integer
Public y As Integer
Public s As String
...
End Class
..
..
..
Public Function Calculate(...) As CalculationResu lt
Dim c As New CalculationResu lt()
c.x = ...
c.y = ...
Return c
End Function
..
..
..
Dim c As CalculationResu lt = 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

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

Similar topics

5
3328
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 charcters in it, that the code needs to run until all bad characters are gone? For example, if a file has the name "<bad*mac\file" the program has to run...
99
5851
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 important changes, so in this thread I would like to focus on that issue alone. I have edited the Proposed Syntax example below to take out the...
21
746
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 read many authors (and it's my belief, too) who discourage the use of the 'inline' keyword, because: - The 'inline' word only advice the compiler...
17
3600
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 deep. In that case you need much more ram than a PC has to store functions calculated in loops so that you do not have to recalculate every time...
2
3767
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 produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently,...
7
5883
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 route. The problem being that I can't call these functions from the query designer in Access. I decided that I would try the route of declaring the...
23
3979
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 who will find them very helpfull. gcc has them as a non-standard option, but only when compiling C language code, so I'm afraid there might be some...
14
4175
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
7
3952
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 functions. Is it normal how C++ Compiler can compile large class without any problem? Didn't C++ Compiler have rules to limit the number of member...
6
9599
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 serialization The code itself generates a list of strings comprised of random numbers. No number will be repeated within a string, and no string will...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.