Converting from a string to a number does not involve parsing embedded arithmetic expressions. In order to do that, you will either have to write your own code to do that, Or, use one that is available for download.
You don't mention whether you are using VB6 or a later version. I've written Expression Evaluators for both.
the VB6 version is part of
BCScriptAfter installing that you could add it in the references (Project->References) dialog and use code like this, once the appropriate controls are added:
Option Explicit
Private ParserObject As CParser
Private Sub cmdEval_Click()
If ParserObject Is Nothing Then
Set ParserObject = new CParser
ParserObject.Create()
End If
Dim XVar as CVariable 'Reference to the Variable we create.
Set XVar = ParserObject.Variables.Add("X",1)
ParserObject.Variables.Add "x",XVar 'make lowercase refer to other variable. (optionally, just ucase the string being evaluated...)
Dim Result As Variant
ParserObject.Expression = txtexpression.Text
ParserObject.ExecuteByRef Result
txtexpression.Text=Result
End Sub
For Visual Basic.NET, you could use my very similar library that is essentially a C# rewrite of my earlier VB6 version,
BASeParser.NET. This one is packaged as a zip file. Extract it somewhere, and then add a reference using Project->Add Reference, and add a reference to BASeParser.dll (from the zip, not the earlier version). Then code like this will work: (again, once the appropriate controls are there)
Imports BASeParser
Public Class Form1
Private ParserObject As CParser
Private XVariable As BASeParser.Variable
Private Sub cmdEval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEval.Click
If ParserObject Is Nothing Then
ParserObject = New CParser()
XVariable = ParserObject.Variables.Add("X", 1.0) '1.0 is needed- (double) (rather than 1 (Integer)) otherwise the Parser will break :(
ParserObject.Variables.Add("X",XVariable) 'make the lower case also refer to the same variable.
End If
Dim Result = ParserObject.Execute(txtEvaluate.Text)
txtEvaluate.Text = Result.ToString()
End Sub
If this is homework, however, using either of those (or any library, for that matter) will probably get you an instant fail... Otherwise you should be set.
EDIT: Note also that Geek-9pm's suggestion has to do with the immediate window, and doesn't actually provide a programmatic method for doing this.