Technical support and scripting issues
Moderators: Dorian (MJT support), JRL
-
shamigc
- Junior Coder
- Posts: 37
- Joined: Wed Oct 22, 2003 11:38 am
- Location: Monterrey, Mexico
Post
by shamigc » Sat Nov 13, 2010 7:11 pm
Hi,
I want to send parameters to a function by reference, but in my test it did not worked out, can you please explain me if this is possible and how can I do it? The code I tried is the following:
Code: Select all
VBSTART
Function t(byval x, byref y)
x=1
y=2
t=true
End Function
VBEND
Let>x=0
Let>y=0
'x should be the same value of 0
'y should change to 2
VBEval>t(x,y),r
MessageModal>%x%,%y%
'x returns 0
'y returns 0
Thanks,
shamigc
Thanks,
Salvador Hernandez
-
adroege
- Automation Wizard
- Posts: 438
- Joined: Tue Dec 07, 2004 7:39 pm
Post
by adroege » Sun Nov 14, 2010 1:58 pm
I don't believe this is possible.
Functions can have only one return value passed back
to Macro Scheduler.
-
shamigc
- Junior Coder
- Posts: 37
- Joined: Wed Oct 22, 2003 11:38 am
- Location: Monterrey, Mexico
Post
by shamigc » Mon Nov 15, 2010 5:41 pm
adroege,
Thank you, I would like to know if people from mjtnet have some special trick to allow this.
Salvador
Thanks,
Salvador Hernandez
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Mon Nov 15, 2010 7:26 pm
This is a VBScript question as you are referring to VBScript functions. You would need to declare the variables as VBScript variables. E.g.
Code: Select all
VBSTART
Function t(byval x, byref y)
x=1
y=20
t=true
End Function
VBEND
VBEval>y=0,r
VBEval>x=3,r
VBEval>t(x,y),res
VBEval>y,r
Note the final result of "r" is 20, because the function has altered the value of y to 20.
-
shamigc
- Junior Coder
- Posts: 37
- Joined: Wed Oct 22, 2003 11:38 am
- Location: Monterrey, Mexico
Post
by shamigc » Mon Nov 15, 2010 10:34 pm
mtettmar,
Hi, thank you for your answer, but in it variables remain at vbscript environment, and I wanted to update more than one macro schedular variable value, when I call a vbscript function, is it possible?
thanks,
shamigc
Thanks,
Salvador Hernandez
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Tue Nov 16, 2010 9:45 am
Well you would need to use VBEval to get a VBScript variable to a MacroScript variable, as I have shown.
-
adroege
- Automation Wizard
- Posts: 438
- Joined: Tue Dec 07, 2004 7:39 pm
Post
by adroege » Thu Mar 10, 2011 3:37 pm
Marcus,
In trying to understand your example, I constructed this. Why
doesn't VBEval>z,r return 8 as I would expect?
Thanks.
Code: Select all
VBSTART
Function t(byref x, byref y, byref z)
z = x + y
t=1
End Function
VBEND
VBEval>y=1,r
VBEval>x=7,r
VBEval>z=0,r
VBEval>t(x,y,z),res
VBEval>z,r
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Thu Mar 10, 2011 3:54 pm
1. in your code z, x an y all only have local scope. That final VBEval will not get the z that is inside your function.
2. The first three evals are returning a boolean as to whether or not the values are set to the values given they are not SETTING those values.
3. This declares z as a global vbscript variable and therefore you can get it's value with VBEval after it has been set by the function:
Code: Select all
VBSTART
Dim z
Function t(byref x, byref y)
z = x + y
t=1
End Function
VBEND
VBEval>t(1,7),res
VBEval>z,r
Not really sure what you are wanting to do.
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Thu Mar 10, 2011 3:57 pm
Or you could do:
Code: Select all
VBSTART
Function t(byval x, byval y, byref z)
z = x + y
t=1
End Function
VBEND
VBEval>t(1,7,z),res
VBEval>z,r
And then variable z exists outside of the function.