Link to home
Start Free TrialLog in
Avatar of brspurri
brspurri

asked on

Script control Procedures

Hello,
I have this text in a textbox that I need to have a script control execute.

'-----------------------
Public Z As Integer

Function X(y As Integer) As Integer
  Z = Y + Z
End Function

Function W(y As Integer) As Integer
  Z = Y - Z
End Function
'------------------------

I need to have the code added to a script control and then be able to call the functions while retaining the Z value.  Is this possible?

Thanks!
Brett
Avatar of Gunsen
Gunsen

I do not know why you have them called functions since the do not return anything, ie: X=Z or W=Z, thus i have made them Sub's in this sample:

  F = F & "Sub X(y)" & vbCr
  F = F & "Z = Y + Z" & vbCr
  F = F & "End Sub" & vbCr
  F = F & "Sub W(y)" & vbCr
  F = F & "Z = Y + Z" & vbCr
  F = F & "End Sub" & vbCr
  ScriptControl1.AddCode F
 
  ScriptControl1.ExecuteStatement "Z=2"
  ScriptControl1.ExecuteStatement ("X(1)")
  ScriptControl1.ExecuteStatement ("W(1)")
  MsgBox ScriptControl1.Eval("Z")
Avatar of brspurri

ASKER

What about the "Public Z As Integer"? I need to keep track of the value of Z as each sub is called.  And thank you, I meant to call them Subs.

-Brett
ASKER CERTIFIED SOLUTION
Avatar of Gunsen
Gunsen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!  One more thing though.  Do you know if you can use Public to reference variables in other modules of the script control (ie: ScriptControl1.Modules("ModA")) ?

Thanks!
I dont believe you can.
brspurri:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Avatar of DanRollins
Moderator, my recommended disposition is:

    Accept Gunsen's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer