Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scriptcontrol.ExecuteStatement doesn't seem to work!

Status
Not open for further replies.

UBfoolin

Programmer
Nov 29, 2001
32
US
dim sc as ScriptControl
dim i as integer

i = 1
sc.ExecuteStatement "i = 25"

At this point, i still equals 1. Why?

Further, if I do:

sc.Eval ( "i = 25" ) it returns False.

Can anyone help me?
 
I presume you are using VB because of 1) your use of strong typing and 2) if it was VBS, you wouldnt need the script control.

Dim i As Integer
i = 1
With ScriptControl1
.ExecuteStatement "i=25"
Debug.Print .Eval("i") 'Prints 25
Debug.Print .Eval("i=25") 'Prints True
Deub.Print i 'Prints 1
End With

Refer to the following for further explanation:
Jon Hawkins
 
Okay, thank you. Your premise was correct. I'm working in VB. This was my misunderstanding. I thought i would end up = 25. It doesn't but .Eval("i") does.

Next, will .Eval or .ExecuteStatement handle an If Then statement? Can you show me an example?

.ExecuteStatement "IF i > j THEN i = 50 ELSE j = 50 END IF"

Thanks for you time.

 
Dim lsMessage As String

For x = 1 To 10
With ScriptControl1
.ExecuteStatement "Dim sVar: Randomize(1): i=Rnd(1): j=Rnd(1)"
lsMessage = "i=" & .Eval("i") & vbTab
lsMessage = lsMessage & "j=" & .Eval("j")
Debug.Print lsMessage
.ExecuteStatement "If i>j Then sVar=""Yes"" Else sVar=""No"""
lsMessage = "Is i > j? " & vbTab
lsMessage = lsMessage & .Eval("sVar")
Debug.Print lsMessage & vbCrLf
End With
Next
Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top