I there a way to return values for multiple variable from a fuction.
The following does not work because it give me a syntax error
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim a As Integer, b As Integer, c As Integer = 1
Dim d As Boolean = False
MsgBox(a & " " & b & " " & c)
d = Testit(a, b, c)
MsgBox(a & " " & b & " " & C)
End Sub
Public Function Testit(ByVal A As Integer, ByVal b As Integer,
ByVal c As Integer) As Boolean
A += 1
b += 1
c += 1
return a, b,c
End Function 4 1339
Hello Jim,
a function can only return ONE variable.
If you want to return several values, you can choose between these options:
1. Use ByRef arguments
2. Return an array or collection
3. Return a string and separate values with a separator (BAD...)
1.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Boolean
A += 1
b += 1
c += 1
Return True ';-)
End Function
'Can also be a Sub...
Public Sub Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer)
A += 1
b += 1
c += 1
End Sub
2.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Integer()
Dim t(2) As Integer
t(0) = A + 1
t(1) = b + 1
t(2) = c + 1
Return t
End Function
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Collection (Of Integer)
Dim c As Collection (Of Integer)
c.Add (A + 1)
c.Add (b + 1)
c.Add (c + 1)
Return c
End Function
3.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As String
Dim s As String
s = CStr(A + 1) & "|"
s &= CStr(b + 1) & "|"
s &= CStr(c + 1) & "|"
Return s
End Function
Best regards,
Martin
On Jun 4, 5:58 am, "Martin H." <h...@gmx.netwrote:
Hello Jim,
a function can only return ONE variable.
If you want to return several values, you can choose between these options:
1. Use ByRef arguments
2. Return an array or collection
3. Return a string and separate values with a separator (BAD...)
1.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Boolean
A += 1
b += 1
c += 1
Return True ';-)
End Function
'Can also be a Sub...
Public Sub Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer)
A += 1
b += 1
c += 1
End Sub
2.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Integer()
Dim t(2) As Integer
t(0) = A + 1
t(1) = b + 1
t(2) = c + 1
Return t
End Function
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As Collection (Of Integer)
Dim c As Collection (Of Integer)
c.Add (A + 1)
c.Add (b + 1)
c.Add (c + 1)
Return c
End Function
3.
Public Function Testit(ByRef A As Integer, ByRef b As Integer,
ByRef c As Integer) As String
Dim s As String
s = CStr(A + 1) & "|"
s &= CStr(b + 1) & "|"
s &= CStr(c + 1) & "|"
Return s
End Function
Best regards,
Martin
You can also use a structure - which is my preferred way of doing
this.
' Typed in message
Public Structure MyStruct
Public Var1 As Integer
Public Var2 As Integer
End Structure
Public Function Foo() As MyStruct
Dim ms As New MyStruct
ms.Var1 = 12
ms.Var2 = 144
Return ms
End Function
Thanks,
Seth Rowe
On Jun 4, 5:32 am, J...@msn.com wrote:
I there a way to return values for multiple variable from a fuction.
The following does not work because it give me a syntax error
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim a As Integer, b As Integer, c As Integer = 1
Dim d As Boolean = False
MsgBox(a & " " & b & " " & c)
d = Testit(a, b, c)
MsgBox(a & " " & b & " " & C)
End Sub
Public Function Testit(ByVal A As Integer, ByVal b As Integer,
ByVal c As Integer) As Boolean
A += 1
b += 1
c += 1
return a, b,c
End Function
I prefer to use a Class object to return multiple values.
"Martin H." <hk***@gmx.netwrote in
news:46***********************@news.freenet.de:
Hello Jim,
a function can only return ONE variable.
If you want to return several values, you can choose between these
options:
1. Use ByRef arguments
2. Return an array or collection
3. Return a string and separate values with a separator (BAD...)
You can return an object or structure - in which case you can send any data
back :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BigDadyWeaver |
last post by:
I am using the following code in asp to define a unique and
unpredictable record ID in Access.
<%
'GENERATE UNIQUE ID
Function genguid()
Dim Guid
guid =...
|
by: Thomas Mlynarczyk |
last post by:
Hi,
I want to pass a variable to a function and that function should display
both the value and the name of that variable. As for the value - no problem,
but the name? So far I've come up with
...
|
by: ad |
last post by:
How to retrun a character with ascii code?
It is useChr(65) return 'A' in VB.NET.
What is the equivalent function in C#?
|
by: Shapper |
last post by:
Hello,
I am declaring a variable in my aspx.vb code as follows:
Public Class catalogue
Public productid As String
Private Sub Page_Load
...
I have an image button where I call the...
|
by: Michael Tissington |
last post by:
I have a C++ function in a DLL of the form
BSTR WINAPI DoSomeWork(LPCSTR szConnection, LPCSTR szGUID)
I use SysAllocStringByteLen to return a BSTR.
For the most part this works accept when...
|
by: kurtgambino |
last post by:
I have crysatl report that uses two parameters that can accept multiple
values. Bur any time more than one value is passed to the parameter it
only stores the last one inputed below is the code it...
|
by: r_o |
last post by:
hi i'm new to this issue
i'm developping a web application with an access database
in my application there's a loop that gets values of a form
like:
lastElt=request("numberOfItems")
for...
|
by: strawberry |
last post by:
In the function below, I'd like to extend the scope of the $table
variable such that, once assigned it would become available to other
parts of the function. I thought 'global $table;' would solve...
|
by: zman77 |
last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine
Hi.
This is my first post, though I've "lurked" for a while because I find these forums very helpful....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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...
|
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...
|
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,...
|
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...
| |