Variables referring into functions/subs
David McFarlane
mcfarla9 at msu.edu
Thu Dec 27 16:32:55 UTC 2012
Not sure I quite follow this, but why not just pass the variable of
interest directly instead of merely passing its name as a String? (I
might also ask why you resort to using Canvas this way in the first
place, but that is another issue.) Using your example,
In global User Script:
Sub CanvasInit( cnvs as Canvas )
cnvs.FillColor = CColor("white")
cnvs.TextColor = CColor("black")
cnvs.Clear
End Sub ' CanvasInit()
In InLine:
Set cnvs = Display.Canvas
cnvs.Text Display.XRes, Display.YRes, "Hello, World!"
Sleep(500)
CanvasInit cnvs
cnvs.text Display.XRes, Display.YRes, "Hello, Sam!"
sleep(500)
Note the lack of parentheses around the argument in the call to
CanvasInit -- unlike rational programming languages like C or MATLAB,
in E-Basic/VBA arguments to Functions *must* be enclosed in
parantheses, while arguments to Subroutines must *not* be enclosed in
parantheses. (Rational programming languages also make no hard
distinction between functions & subroutines, but again, that is
another matter.)
-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster)
/----
Stock reminder: 1) I do not work for PST. 2) PST's trained staff
take any and all questions at
http://support.pstnet.com/e%2Dprime/support/login.asp , and they
strive to respond to all requests in 24-48 hours, so make full use of
it. 3) In addition, PST offers several instructional videos on their
YouTube channel (http://www.youtube.com/user/PSTNET ). 4) If you do
get an answer from PST staff, please extend the courtesy of posting
their reply back here for the sake of others.
\----
At 12/26/2012 06:40 PM Wednesday, sam wrote:
>Hello! I'm working on some experiments for the lab in which I
>work. I've run into some problems in the coding side, and I hoped I
>could find some help here.
>
>I'm having some problems with variables. I'll make up an example,
>where I'm attempting to pass a string into a function. I want to
>use the contents of this string as a the name of any canvas I
>choose, so I can clear any canvas by sending it's name into this subroutine.
>
>*****
>
>'userscript
>dim canvas as slide
>
>Sub clearcanvas(namecnvs as string)
> Set namecnvs = Display.Canvas
> namecnvs.FillColor = CColor("white")
> namecnvs.TextColor = CColor("black")
> namecnvs.Clear
>end sub
>
>
>'inline
>Set cnvs = Display.Canvas
>cnvs.text Display.XRes, Display.YRes, "Hello, World!"
>
>sleep(500)
>Call clearcanvas("cnvs")
>
>cnvs.text Display.XRes, Display.YRes, "Hello, Sam!"
>sleep(500)
>
>*****
>
>Now obviously, I can't use "cnvs" like that, but it's a great way In
>this example, what I want to do is use the contents of the string
>namecnvs to represent the name of any canvas I desire, but I don't
>know how. When using namecnvs as is, e-prime would treat it as
>another slide. I can't find anything in e-prime that would allow me
>to either identify something as a variable (like a $ in bash) or use
>it's contents dynamically. I can do this in bash and matlab, and in
>C, but I can't figure out how to do this in E-Prime. I could do
>some really neat things (I find scripting to be neat) if I could
>just nail this issue.
>
>Thank you for your time, and happy holidays!
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
More information about the Eprime
mailing list