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

Get value from formula 1

Status
Not open for further replies.

DavidSL

Programmer
Jul 7, 2003
15
0
0
US
I retrive some data like "56+88/12" from database. It's considered as string. How to get the value from it?
Thanks in advance!
 
Look up the Eval function - it will get you started

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks for your quick response John!
Is EVal function available with VB?
 
dont think its in VB as is, but u can get round it by adding a reference to the excel object library

Code:
Dim xl As Excel.Application

Private Sub Command1_Click()

Set xl = New Excel.Application

strstr = "56+88/12"

Text1 = xl.Evaluate(strstr)

Set xl = Nothing

End Sub

there may be an easier way but for now good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
Using Excel seems a bit...extreme. A more lightweight solution would be to add a reference to the Microsoft Script Control, and then use a function similar to this:

Public Function vbEval(strSource As String) As Variant
With New ScriptControl
.Language = "vbscript"
vbEval = .Eval(strSource)
End With
End Function
 
Sorry I'm late back. When I said <Look up the Eval function > I meant look in VBHelp - it tells you that eval is a Scriptcontrol function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
>there may be an easier way but for now good luck!

phew... im glad i covered my back [wink]

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top