# Visual Basic Eval



## Guy (Feb 19, 1999)

I am using the Eval() function to test for syntax errors in an expression builder and I have come upon a case where the eval function does not generate an error when It should. The expression I enter is *Eval("1.1.1")* and instead of raising an error, it returns *0*. This also seems to work if you replace the 1's with any other single digit number.

I'm just wondering if there is a fix for this or if there is a reason it does not raise an error.

Anybody got any ideas?

Thanks
- Guy


----------



## TimCottee (Oct 10, 2001)

Interesting, I have just tried it myself and I do get an error: 1002 (Syntax Error). I have version 1.0.0.4615 of the MSScript.ocx running on Win2ksp2 with VB SP5.

Not a lot of help there I know, are you sure there is no error handling or anything that may cause this apparent problem?


----------



## Guy (Feb 19, 1999)

I goofed my topic title. I just took a second look, and the Eval function I am using is actually coming from the Microsoft Access 9.0 Object Library (MSACC9.OLB) v. 9.0.0.2719 on Windows XP Pro (w/ all windows updates). The office I am using is 2000 Professional SP1.

I often forget that Office VBA and VB are quite different.


----------



## Guy (Feb 19, 1999)

Okay, I tried to use the (1.0.0.6626) MSScript Control's eval function but I cannot get the control to initialize. I am trying to initialize the control strictly through code because the function that needs it is used across many different forms and is stored in a global module. Right now I have this:

```
Dim sc As MSScriptControl.ScriptControl
Set sc = New MSScriptControl.ScriptControl
sc.Reset
sc.Language = "VBScript"
sc.AllowUI = True

Debug.Print sc.Eval("1 + 2")
```
I get an error stating "The operation could not be completed because the script engine has not been initialized to a valid language." when I use this code. It does the same thing when I take out the sc.Language line as well.

Is it even possible to initialize this without having the control on a form?

- Guy


----------



## TimCottee (Oct 10, 2001)

Guy, it is but you should remove the sc.reset line or move it after the language line:


```
Dim sc As MSScriptControl.ScriptControl
Set sc = New MSScriptControl.ScriptControl
sc.Language = "VBScript"
sc.Reset
sc.AllowUI = True

Debug.Print sc.Eval("1+2")
```
I have just tried this in Word 2K SP1 and it is fine!


----------



## Guy (Feb 19, 1999)

Thanks Tim.

It is working like it should with the Script control's eval. Still sorta weird that the Access 9.0 library's eval doesnt catch that error. Anyway, thanks again for your help.

- Guy


----------



## TimCottee (Oct 10, 2001)

Indeed it is Guy, never used that particular library myself and will probably avoid it like the plague from now on. Happy to have helped though.


----------

