473,386 Members | 1,803 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,386 software developers and data experts.

Return Values

384 256MB
I'm having a problem with returning values from a function.

No matter what I do I can't return values from another function to store in a variable. Any help much appreciated!

Say I have:
Expand|Select|Wrap|Line Numbers
  1. Public Sub MainFunc()
  2.   result = test "param1","param2"
  3. End Sub
  4.  
  5. Private Sub test(param1In,param2In)
  6.   {return value}
  7. End Sub
Jul 13 '10 #1

✓ answered by vb5prgrmr

Function = As Something...
Expand|Select|Wrap|Line Numbers
  1. Private Function MyFunction (MyInput As String) As String
  2. MyFunction = MyInput
  3. End Function
  4.  


Good Luck

4 1117
ziycon
384 256MB
Ok, I've gotten a bit further, I release I should have been using Function instead of Sub, can someone tell me the difference?

I've changed the code to be like below but its still crashing out at the function call?

Expand|Select|Wrap|Line Numbers
  1. Public Function MainFunc(param1In,param2In)
  2.   result = test(param1In,param2In)
  3.  
  4.   Console.Write result
  5. End Function
  6.  
  7. Private Function test(param1In,param2In)
  8.   Dim answer
  9.  
  10.   answer = param1In + param2In
  11.  
  12.   Set test = answer
  13. End Function
Jul 13 '10 #2
vb5prgrmr
305 Expert 100+
Function = As Something...
Expand|Select|Wrap|Line Numbers
  1. Private Function MyFunction (MyInput As String) As String
  2. MyFunction = MyInput
  3. End Function
  4.  


Good Luck
Jul 13 '10 #3
ziycon
384 256MB
I'm slightly confused, I understand the example you gave, just not 100% sure how it would handle multiple parameters?

Expand|Select|Wrap|Line Numbers
  1. Private Function test(param1In,param2In)
  2.   Dim answer
  3.   answer = param1In + param2In
  4.   test = answer
  5. End Function
Jul 13 '10 #4
ziycon
384 256MB
Got it working, thanks for your help.
Jul 13 '10 #5

Sign in to post your reply or Sign up for a free account.

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()
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...
18
by: skishorev | last post by:
Hi, Here I am taking two functions. void f(int,int) and another one is float f(int,int). Is it possible to overload with return values. Thx, kishore
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...
17
by: binjobster | last post by:
Hello everyone, I'm updating some documents that describes so many C/C++ functions/method(about 2500). But I'm not familiar with these codes. So I want to find such a utility can generate...
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...
4
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. ...
14
by: =?Utf-8?B?QmVu?= | last post by:
Hi all, I'm trying to understand the concept of returning functions from the enclosing functions. This idea is new to me and I don't understand when and why I would need to use it. Can someone...
1
by: ziycon | last post by:
I'm getting to grips with ASP Classic using VBScript. I'm having a problem with returning values from a function. No matter what I do I can't return values from another function to store in a...
0
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...

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.