Eval function Blank Title 92009

Impressive. :-)

-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Steven Gotschall
Sent: Thursday, July 22, 2010 11:00 AM
To: vantage@yahoogroups.com
Subject: Re: [Vantage] Eval function

Thanks everyone for you help, but I finally found a solution that works great.Â

To use this namespace and evaluate a string as an equation:

Dim ep As New PAB.Util.EvalProvider
MsgBox(ep.Eval("Return (23 * 3) / 8"))
Â
ep.Eval will compile the string and return the results as an object. Since all
I needed was to evaluate and equation, I added a Return in front of the equation
(turning the string into a one line function). You could pass it many lines of
code and have it return just about anything, including a dataset.
Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In other words, I have a formula like "(240 / 2) + 10" and I want to evaluate it and have it return 130.
The DECIMAL and INTEGER functions will take a string input and return
the result.

-bws

-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Steven
Sent: Wednesday, July 21, 2010 5:07 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Eval function

Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In
other words, I have a formula like "(240 / 2) + 10" and I want to
evaluate it and have it return 130.



------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
The Decimal and Integer functions only convert a string to a number. It won't
evaluate it as an equation. Also, I was hoping for something that could be used
in a form customization, but if it can be done in 4gl that would be OK.




________________________________
From: Brian W. Spolarich <bspolarich@...>
To: vantage@yahoogroups.com
Sent: Wed, July 21, 2010 5:12:31 PM
Subject: RE: [Vantage] Eval function

Â
The DECIMAL and INTEGER functions will take a string input and return
the result.

-bws

-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Steven
Sent: Wednesday, July 21, 2010 5:07 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Eval function

Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In
other words, I have a formula like "(240 / 2) + 10" and I want to
evaluate it and have it return 130.

------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links







[Non-text portions of this message have been removed]
If you're trying to convert string "(240 / 2) + 10" you will need to
write your own function.



Common string manipulation uses left, right, mid, string length, trim,
conversion of string to int or float. There isn't a predefined function
for these.



Daniel







From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Steven Gotschall
Sent: Thursday, July 22, 2010 6:13 AM
To: vantage@yahoogroups.com
Subject: Re: [Vantage] Eval function





The Decimal and Integer functions only convert a string to a number. It
won't
evaluate it as an equation. Also, I was hoping for something that could
be used
in a form customization, but if it can be done in 4gl that would be OK.

________________________________
From: Brian W. Spolarich <bspolarich@...
<mailto:bspolarich%40advancedphotonix.com> >
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Sent: Wed, July 21, 2010 5:12:31 PM
Subject: RE: [Vantage] Eval function


The DECIMAL and INTEGER functions will take a string input and return
the result.

-bws

-----Original Message-----
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf
Of Steven
Sent: Wednesday, July 21, 2010 5:07 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] Eval function

Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In
other words, I have a formula like "(240 / 2) + 10" and I want to
evaluate it and have it return 130.

------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
<http://groups.yahoo.com/group/vantage/files/>
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links

[Non-text portions of this message have been removed]



________________________________



[Non-text portions of this message have been removed]
Sorry I provided misinformation. :-)

-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Daniel Milano
Sent: Thursday, July 22, 2010 10:23 AM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] Eval function

If you're trying to convert string "(240 / 2) + 10" you will need to
write your own function.



Common string manipulation uses left, right, mid, string length, trim,
conversion of string to int or float. There isn't a predefined function
for these.



Daniel







From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Steven Gotschall
Sent: Thursday, July 22, 2010 6:13 AM
To: vantage@yahoogroups.com
Subject: Re: [Vantage] Eval function





The Decimal and Integer functions only convert a string to a number. It
won't
evaluate it as an equation. Also, I was hoping for something that could
be used
in a form customization, but if it can be done in 4gl that would be OK.

________________________________
From: Brian W. Spolarich <bspolarich@...
<mailto:bspolarich%40advancedphotonix.com> >
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Sent: Wed, July 21, 2010 5:12:31 PM
Subject: RE: [Vantage] Eval function


The DECIMAL and INTEGER functions will take a string input and return
the result.

-bws

-----Original Message-----
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf
Of Steven
Sent: Wednesday, July 21, 2010 5:07 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] Eval function

Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In
other words, I have a formula like "(240 / 2) + 10" and I want to
evaluate it and have it return 130.

------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
<http://groups.yahoo.com/group/vantage/files/>
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links

[Non-text portions of this message have been removed]



________________________________



[Non-text portions of this message have been removed]



------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links
Thanks everyone for you help, but I finally found a solution that works great.Â
Here is the code I added at the beginning of my customization:

Imports System
Imports System.Data
Imports System.IO
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Math
Imports System.Drawing
Imports System.Text
Imports Microsoft.VisualBasic
Imports Epicor.Mfg.UI
Imports Epicor.Mfg.UI.FrameWork
Imports Epicor.Mfg.UI.ExtendedProps
Imports Epicor.Mfg.UI.FormFunctions
Imports Epicor.Mfg.UI.Customization
Imports Epicor.Mfg.UI.Adapters
Imports Epicor.Mfg.UI.Searches
Imports Epicor.Mfg.BO
Imports System.collections
Imports System.Reflection
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports System.CodeDom.Compiler
Namespace PAB.Util
   Public Class EvalProvider
       Public Function Eval(ByVal vbCode As String) As Object
           Dim c As VBCodeProvider = New VBCodeProvider
           Dim icc As ICodeCompiler = c.CreateCompiler()
           Dim cp As CompilerParameters = New CompilerParameters
           cp.ReferencedAssemblies.Add("system.dll")
           cp.ReferencedAssemblies.Add("system.xml.dll")
           cp.ReferencedAssemblies.Add("system.data.dll")
           ' Sample code for adding your own referenced assemblies
          Â
'cp.ReferencedAssemblies.Add("c:\yourProjectDir\bin\YourBaseClass.dll")
           'cp.ReferencedAssemblies.Add("YourBaseclass.dll")
           cp.CompilerOptions = "/t:library"
           cp.GenerateInMemory = True
           Dim sb As StringBuilder = New StringBuilder("")
           sb.Append("Imports System" & vbCrLf)
           sb.Append("Imports System.Xml" & vbCrLf)
           sb.Append("Imports System.Data" & vbCrLf)
           sb.Append("Imports System.Data.SqlClient" & vbCrLf)
           sb.Append("Namespace PAB " & vbCrLf)
           sb.Append("Class PABLib " & vbCrLf)
           sb.Append("public function EvalCode() as Object " & vbCrLf)
           'sb.Append("YourNamespace.YourBaseClass thisObject = New
YourNamespace.YourBaseClass()")
           sb.Append(vbCode & vbCrLf)
           sb.Append("End Function " & vbCrLf)
           sb.Append("End Class " & vbCrLf)
           sb.Append("End Namespace" & vbCrLf)
           Debug.WriteLine(sb.ToString()) ' look at this to debug your eval
string
           Dim cr As CompilerResults = icc.CompileAssemblyFromSource(cp,
sb.ToString())
           Dim a As System.Reflection.Assembly = cr.CompiledAssembly
           Dim o As Object
           Dim mi As MethodInfo
           o = a.CreateInstance("PAB.PABLib")
           Dim t As Type = o.GetType()
           mi = t.GetMethod("EvalCode")
           Dim s As Object
           s = mi.Invoke(o, Nothing)
           Return s
       End Function
   End Class
End Namespace
Â
To use this namespace and evaluate a string as an equation:

Dim ep As New PAB.Util.EvalProvider
MsgBox(ep.Eval("Return (23 * 3) / 8"))
Â
ep.Eval will compile the string and return the results as an object. Since all
I needed was to evaluate and equation, I added a Return in front of the equation
(turning the string into a one line function). You could pass it many lines of
code and have it return just about anything, including a dataset.




________________________________
From: Steven Gotschall <sgotschall@...>
To: vantage@yahoogroups.com
Sent: Thu, July 22, 2010 7:13:29 AM
Subject: Re: [Vantage] Eval function


The Decimal and Integer functions only convert a string to a number. It won't
evaluate it as an equation. Also, I was hoping for something that could be used
in a form customization, but if it can be done in 4gl that would be OK.




________________________________
From: Brian W. Spolarich <bspolarich@...>
To: vantage@yahoogroups.com
Sent: Wed, July 21, 2010 5:12:31 PM
Subject: RE: [Vantage] Eval function

Â
The DECIMAL and INTEGER functions will take a string input and return
the result.

-bws

-----Original Message-----
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf
Of Steven
Sent: Wednesday, July 21, 2010 5:07 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Eval function

Vantager 8.03.408a Progress

Anyone have a good way to evaluate a formula stored as a string? In
other words, I have a formula like "(240 / 2) + 10" and I want to
evaluate it and have it return 130.

------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must
have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder
and Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links








[Non-text portions of this message have been removed]