By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,392 Members | 1,556 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,392 IT Pros & Developers. It's quick & easy.

Names of the variables as SUB arguments

P: n/a
I countinue to discover problems for simple tasks. Now I would like to
write code, Sub or Function, where some values (more than 1) are
calculated and are to be assigned to the variables which names I would
like to submit as arguments to this SUB /Function
How to do this.

--
Vlad. Moltchanov
Nov 12 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Use the ByRef option in the arguments list of the function. Perform your
calculations, set the new values, and your calling function can then use the
new values of the variables.

Mike Storr
www.veraccess.com
<vl******************@ktl.fi> wrote in message
news:40***************@ktl.fi...
I countinue to discover problems for simple tasks. Now I would like to
write code, Sub or Function, where some values (more than 1) are
calculated and are to be assigned to the variables which names I would
like to submit as arguments to this SUB /Function
How to do this.

--
Vlad. Moltchanov

Nov 12 '05 #2

P: n/a
vl******************@ktl.fi wrote:
I countinue to discover problems for simple tasks. Now I would like to
write code, Sub or Function, where some values (more than 1) are
calculated and are to be assigned to the variables which names I would
like to submit as arguments to this SUB /Function
How to do this.


Something looking like?

sub setValues(name1, value1, name2, value2)
(name1) = value1
(name2) = value2
end sub

?

I think that is not possible. Moreover, the variables assigned to must
be global, or at least with a scope larger than the sub itself--why use
such global variables? Can't you use a table, say Settings(settingName,
settingValue)?
--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #3

P: n/a
Bas Cost Budde <ba*@heuveltop.org> wrote in
news:c0***********@news2.solcon.nl:
vl******************@ktl.fi wrote:
I countinue to discover problems for simple tasks. Now I would
like to write code, Sub or Function, where some values (more than
1) are calculated and are to be assigned to the variables which
names I would like to submit as arguments to this SUB /Function
How to do this.


Something looking like?

sub setValues(name1, value1, name2, value2)
(name1) = value1
(name2) = value2
end sub

?

I think that is not possible. Moreover, the variables assigned to
must be global, or at least with a scope larger than the sub
itself--why use such global variables? Can't you use a table, say
Settings(settingName, settingValue)?


Eh?

If you pass ByRef (the default), then the values will work.

Call your sub thusly:

Dim OutsideVariable1
Dim OutsideVariable2

setValues OutsideVariable1, "foo", OutsideVariable2, "bar"

Debug.Print OutsideVariable1 & " " & OutsideVariable2

will return:

foo bar

in the debug window.

That's how you can get multiple values returned from a sub/function,
by passing variables by reference that are written to within the
sub/function.

This is a basic technique of VB.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #4

P: n/a
David W. Fenton wrote:
Bas Cost Budde <ba*@heuveltop.org> wrote in
I think that is not possible.

Eh?


Exactly! Eh? I COMPLETELY misunderstood the question. Sorry about that,
happily I'm not the only one in the team.

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Nov 12 '05 #5

P: n/a
Bas Cost Budde <ba*@heuveltop.org> wrote in
news:c0**********@news2.solcon.nl:
David W. Fenton wrote:
Bas Cost Budde <ba*@heuveltop.org> wrote in

I think that is not possible.

Eh?


Exactly! Eh? I COMPLETELY misunderstood the question. Sorry about
that, happily I'm not the only one in the team.


Well, it's also possible *you* understood it and *I* didn't!

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #6

P: n/a
Thanks to all having replied.

The idea of ByRef became much more clear. However, my task was to make
an Access analog of SAS macro taking as an argument string like "name1
name2 ... name5" (number of names is not fixed) and generating
variables

name1 name2 ... name5 with, say, consequitive random numbers.

vl******************@ktl.fi wrote:

I countinue to discover problems for simple tasks. Now I would like to
write code, Sub or Function, where some values (more than 1) are
calculated and are to be assigned to the variables which names I would
like to submit as arguments to this SUB /Function
How to do this.

--
Vlad. Moltchanov


--
Vladislav Moltchanov Ph.D.

National Public Health Institute
Dept. of Epidemiology and Health Promotion
Mannerheimintie 166, 00300 Helsinki, Finland

Tel: +358 9 4744 8644
Fax: +358 9 4744 8338
Nov 12 '05 #7

P: n/a
On Mon, 09 Feb 2004 16:59:26 +0200, vl******************@ktl.fi wrote:
I countinue to discover problems for simple tasks. Now I would like to
write code, Sub or Function, where some values (more than 1) are
calculated and are to be assigned to the variables which names I would
like to submit as arguments to this SUB /Function
How to do this.


Are you sure what you're talking about isn't best simply handled with arrays
or collections? Parsing the names of things at run-time just to get numbered
lists is very inefficient, to the extent it's possible at all.
Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.