SimpleEval

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

SimpleEval

Charlie
Hi Fabian,

I presume that you wrote the code in SimpleEval. I can't work out how to use it. I thought it might work with my gbCalculator (see Gmabas Farm). There are quite a few compile warning errors.

The main thing is some examples on how to use it please.

Thanks.

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
You get the class from where ?


2015-12-29 15:18 GMT+01:00 Charlie <[hidden email]>:

> Hi Fabian,
> I presume that you wrote the code in SimpleEval. I can't work out how to use
> it. I thought it might work with my gbCalculator (see Gmabas Farm). There
> are quite a few compile warning errors.
> <http://gambas.8142.n7.nabble.com/file/n55114/CompileErrors.png>
> *The main thing is some examples on how to use it please.*
> Thanks.
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.com/SimpleEval-tp55114.html
> Sent from the gambas-user mailing list archive at Nabble.com.
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user



--
Fabien Bodard

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
>From the Main Module in the Farm example :


Public Sub Main()
  Dim hEval As New SimpleEval As "Eval"
  Dim hEx As New EvalEx As "Eval"

  'Test with an unknown variable
  hEval.Formula = "IF(Test=1;'TROUVE';'PERDU')"
  hEval.Execute
  If Not hEval.Error Then
    Print hEval.Value
  Else
    Print hEval.ErrorText
  Endif


  'Test extention
  hEx.Formula = "Message('coucou')"
  hEx.Execute

  'Test Both
   hEx.Formula = "Message(If(Test=1;'TROUVE ' & prenom;'PERDU'))"
  hEx.Execute

  'Test Calculation
  hEx.Formula = "Cos(1)+pi()*2^mypower"
  hEx.Execute
  Print hEx.Value

End


Public Sub Eval_Data(Value As String)

  If Value = "Test" Then
    Last.data = 1
  Endif
  If Value = "mypower" Then
    Last.data = 3
  Endif
  If Value = "prenom" Then Last.Data = "Fabien"


End

2015-12-30 7:10 GMT+01:00 Fabien Bodard <[hidden email]>:

> You get the class from where ?
>
>
> 2015-12-29 15:18 GMT+01:00 Charlie <[hidden email]>:
>> Hi Fabian,
>> I presume that you wrote the code in SimpleEval. I can't work out how to use
>> it. I thought it might work with my gbCalculator (see Gmabas Farm). There
>> are quite a few compile warning errors.
>> <http://gambas.8142.n7.nabble.com/file/n55114/CompileErrors.png>
>> *The main thing is some examples on how to use it please.*
>> Thanks.
>>
>>
>>
>> --
>> View this message in context: http://gambas.8142.n7.nabble.com/SimpleEval-tp55114.html
>> Sent from the gambas-user mailing list archive at Nabble.com.
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> Gambas-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
>
> --
> Fabien Bodard



--
Fabien Bodard

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
you can get the error and the error pos too,

i've updated the class on the farm to remove the compilation warnings

2015-12-30 7:21 GMT+01:00 Fabien Bodard <[hidden email]>:

> From the Main Module in the Farm example :
>
>
> Public Sub Main()
>   Dim hEval As New SimpleEval As "Eval"
>   Dim hEx As New EvalEx As "Eval"
>
>   'Test with an unknown variable
>   hEval.Formula = "IF(Test=1;'TROUVE';'PERDU')"
>   hEval.Execute
>   If Not hEval.Error Then
>     Print hEval.Value
>   Else
>     Print hEval.ErrorText
>   Endif
>
>
>   'Test extention
>   hEx.Formula = "Message('coucou')"
>   hEx.Execute
>
>   'Test Both
>    hEx.Formula = "Message(If(Test=1;'TROUVE ' & prenom;'PERDU'))"
>   hEx.Execute
>
>   'Test Calculation
>   hEx.Formula = "Cos(1)+pi()*2^mypower"
>   hEx.Execute
>   Print hEx.Value
>
> End
>
>
> Public Sub Eval_Data(Value As String)
>
>   If Value = "Test" Then
>     Last.data = 1
>   Endif
>   If Value = "mypower" Then
>     Last.data = 3
>   Endif
>   If Value = "prenom" Then Last.Data = "Fabien"
>
>
> End
>
> 2015-12-30 7:10 GMT+01:00 Fabien Bodard <[hidden email]>:
>> You get the class from where ?
>>
>>
>> 2015-12-29 15:18 GMT+01:00 Charlie <[hidden email]>:
>>> Hi Fabian,
>>> I presume that you wrote the code in SimpleEval. I can't work out how to use
>>> it. I thought it might work with my gbCalculator (see Gmabas Farm). There
>>> are quite a few compile warning errors.
>>> <http://gambas.8142.n7.nabble.com/file/n55114/CompileErrors.png>
>>> *The main thing is some examples on how to use it please.*
>>> Thanks.
>>>
>>>
>>>
>>> --
>>> View this message in context: http://gambas.8142.n7.nabble.com/SimpleEval-tp55114.html
>>> Sent from the gambas-user mailing list archive at Nabble.com.
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> Gambas-user mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>>
>>
>> --
>> Fabien Bodard
>
>
>
> --
> Fabien Bodard



--
Fabien Bodard

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
In fact internally it use two process.

the first one when you set the formula. It compile it... understand
reorganize and traduce the formula into interpreter readable
sequences.
The second one when you call Execute, the interpreter read the stored sequence.
During this process if some variables are used the interpreter raise
the data event and give the required var name. So you can give it
throuth the .data property.


Internally the interpreter have bridges to every math and string
common functions of Gambas. You can extent the functions by inheriting
the simpleEval and adding your own function.

example :

Export
Inherits SimpleEval

Public Sub _New()

  SimpleEval.Functions.Add("Message")
  SimpleEval.FunctionsArgsCount.Add(1)

End


''Show a windowed message
Public Sub _MESSAGE(Val1 As CResult) As CResult

  Message(Val1.Value)
  Return New CResult(Null, CResult.TypeValue)

End

Void not exist, you must return a null result on a void function.


Simple eval does what i need... a simple extendable formula
interpreter like the one we can se on spreadsheet. I use it now on
report too.
So i can say now "='Page ' & page & ' on ' & pages"

I forgot " and ' are accepted for string delemiter


2015-12-30 7:21 GMT+01:00 Fabien Bodard <[hidden email]>:

> you can get the error and the error pos too,
>
> i've updated the class on the farm to remove the compilation warnings
>
> 2015-12-30 7:21 GMT+01:00 Fabien Bodard <[hidden email]>:
>> From the Main Module in the Farm example :
>>
>>
>> Public Sub Main()
>>   Dim hEval As New SimpleEval As "Eval"
>>   Dim hEx As New EvalEx As "Eval"
>>
>>   'Test with an unknown variable
>>   hEval.Formula = "IF(Test=1;'TROUVE';'PERDU')"
>>   hEval.Execute
>>   If Not hEval.Error Then
>>     Print hEval.Value
>>   Else
>>     Print hEval.ErrorText
>>   Endif
>>
>>
>>   'Test extention
>>   hEx.Formula = "Message('coucou')"
>>   hEx.Execute
>>
>>   'Test Both
>>    hEx.Formula = "Message(If(Test=1;'TROUVE ' & prenom;'PERDU'))"
>>   hEx.Execute
>>
>>   'Test Calculation
>>   hEx.Formula = "Cos(1)+pi()*2^mypower"
>>   hEx.Execute
>>   Print hEx.Value
>>
>> End
>>
>>
>> Public Sub Eval_Data(Value As String)
>>
>>   If Value = "Test" Then
>>     Last.data = 1
>>   Endif
>>   If Value = "mypower" Then
>>     Last.data = 3
>>   Endif
>>   If Value = "prenom" Then Last.Data = "Fabien"
>>
>>
>> End
>>
>> 2015-12-30 7:10 GMT+01:00 Fabien Bodard <[hidden email]>:
>>> You get the class from where ?
>>>
>>>
>>> 2015-12-29 15:18 GMT+01:00 Charlie <[hidden email]>:
>>>> Hi Fabian,
>>>> I presume that you wrote the code in SimpleEval. I can't work out how to use
>>>> it. I thought it might work with my gbCalculator (see Gmabas Farm). There
>>>> are quite a few compile warning errors.
>>>> <http://gambas.8142.n7.nabble.com/file/n55114/CompileErrors.png>
>>>> *The main thing is some examples on how to use it please.*
>>>> Thanks.
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://gambas.8142.n7.nabble.com/SimpleEval-tp55114.html
>>>> Sent from the gambas-user mailing list archive at Nabble.com.
>>>> ------------------------------------------------------------------------------
>>>> _______________________________________________
>>>> Gambas-user mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>>
>>>
>>> --
>>> Fabien Bodard
>>
>>
>>
>> --
>> Fabien Bodard
>
>
>
> --
> Fabien Bodard



--
Fabien Bodard

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Charlie
Can I get your code to calculate something like

28*(5/2.3)

If so how?

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
2015-12-30 17:37 GMT+01:00 Charlie <[hidden email]>:
> Can I get your code to calculate something like
> 28*(5/2.3)
> If so how?
 Dim hEval As New SimpleEval


  hEval.Formula = "28*(5/2.3)"
  hEval.Execute

  If Not hEval.Error Then
    Print hEval.Value
  Else
    Print hEval.ErrorText
  Endif

------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Charlie
Thanks, that's excellent. I will work on that.

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Charlie
This is working out well! Your code can handle some complex maths.

Is there any way to handle negative numbers? If an answer is negative it works but if you input "-5*6" it does not work.

I have also attached my code, still in development, so you can see what I am doing with your code.

gbCalculator.tar

Check out www.gambas.one

Reply | Threaded
Open this post in threaded view
|

Re: SimpleEval

Fabien Bodard-4
Le 31 déc. 2015 15:36, "Charlie" <[hidden email]> a écrit :
>
> This is working out well! Your code can handle some complex maths.
> Is there any way to handle negative numbers? If an answer is negative it
> works but if you input "*-5*6*" it does not work.
> I have also attached my code, still in development, so you can see what I
am
> doing with your code.
> <http://gambas.8142.n7.nabble.com/file/n55141/gbCalculator.png>
> gbCalculator.tar
> <http://gambas.8142.n7.nabble.com/file/n55141/gbCalculator.tar>
>
It's a bug... I will correct that.
>
> --
> View this message in context:
http://gambas.8142.n7.nabble.com/SimpleEval-tp55114p55141.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------------------------------------------------------------------------------
_______________________________________________
Gambas-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user