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

String - Float Conversion 1

Status
Not open for further replies.

selimsl

Programmer
Aug 15, 2005
62
TR
Hi!

I have a string(a) which consists of a number(5) and a variable(z). I replace z with 2 using replace function.
and I want to get 7 as result(x). Is there any function to get right result.

Code:
Dim a As String
Dim x As Long
a = "(z + 5)"

a = Replace(a, "z", "2")
x = Val(a)

Thanks..
 
Try this:

Code:
Private Sub Command1_Click()
Dim a As String
Dim x As Long
a = "z + 5"

a = Replace(a, "z", "2")
x = CInt(Left(a, 1)) + CInt(Right(a, 1))
MsgBox x
End Sub
 
Dim a As String
Dim x As Long

a = "(z + 5)"
With CreateObject("MSScriptControl.ScriptControl")
.Language = "vbscript"
.ExecuteStatement ("z = 2") '
x = .eval(a)
End With
MsgBox x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top