• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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
0
brspurri
Asked:
brspurri
1 Solution
 
GunsenCommented:
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")
0
 
brspurriAuthor Commented:
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
0
 
GunsenCommented:
Sorry, the Z was missing from my copy-paste...
Add to the top:
F = "Dim Z"

Then the Z will remain persistent.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
brspurriAuthor Commented:
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!
0
 
GunsenCommented:
I dont believe you can.
0
 
CleanupPingCommented:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now