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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 and VBScript 2

Status
Not open for further replies.

drathbone

Technical User
Jun 11, 2001
39
GB
Ok, it's a stupid question, but how do I execute a bit of VBScript code inside a VB6 application (need to use the eval function) ??

Cheers
 
Hi,

Add the MS script control to a form in your project.
Use can then use the eval method. E.g.
----------------------------------------------------------
Dim n As Integer
ScriptControl1.ExecuteStatement ("i=2")
n = ScriptControl1.Eval("i+1")
MsgBox (n)
---------------------------------------------------------- Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
This will sound stupid, but I can't find the MS SCript Control anywhere !!!
I've got VB6 Pro installed... is it a seperate item ?
 
Not a stupid question at all.

Ok, first of all you need to add a refererence to the Microsoft Script Control (although you can do late binding and avoid the reference if you prefer). Then, for this example, you need a form with a textbox, a label and a command button. You will be able to enter calcuations into the textbox (e.g 2+5, (2+6)/4), and hit the command button to get the result in the label. You just need to drop in the following code:
[tt]
Option Explicit

Private Sub Command1_Click()
Dim wsh As ScriptControl 'Change to As Object if you don't want to add a refference

' Done this way rather than with New to cater for the fact we may have decided not to add a reference
' and therefore wsh may be declared As Object.
Set wsh = CreateObject("MSScriptControl.ScriptControl")

wsh.Language = "vbscript" ' Vital - must tell script control which of the several script languages it is to use

Label1 = wsh.Eval(Text1.Text)
End Sub
 
Top info from both of you, which will eventually solve my problem, but I still can't find the MS Script Control !!
 
sorry... got the control now.

Thanks for all your help...
 
In the Project menu, select Components. Make sure "Selected Items Only" is unchecked. Then select "Microsoft Script Control x.x" from the list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top