My EVAL for use with BBC BASIC

Discussions related to the supplied tools and add-in utilities
ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

My EVAL for use with BBC BASIC

Post by ivega718 »

The code is working fine with LBB. Please if somebody can help me for return numeric values in BBC BASIC. This is code with BBC BASIC:

Code: Select all

      SYS "LoadLibrary", "EVAL.DLL" TO EVDLL%
      SYS "GetProcAddress", EVDLL%, "ExeBasic" TO ExeBasic%
      SYS "GetProcAddress", EVDLL%, "GetValue" TO GetValue%
      SYS ExeBasic%, "TestNUM1#=1200.25",0,1 TO result%
      SYS ExeBasic%, "TestNUM2#=1401.18",0,1 TO result%
      SYS ExeBasic%, "TOTAL#=TestNUM1#+TestNUM2#",0,1 TO result%
      SYS ExeBasic%, "MSGBOX TOTAL#",0,1 TO resultado
      SYS GetValue%, "TOTAL#",0,1 TO resultado_total
      PRINT resultado_total
      SYS "FreeLibrary", EVDLL%
This is code using LBB and is working fine:

Code: Select all

'Sample with LBB from a text file
'using EVAL.DLL and execute code from a text file
'
OPEN "CODE.TXT" FOR BINARY AS #BUFFER
code$=Input$(#BUFFER,3267)
CLOSE #1
notice code$
open "EVAL.DLL" for dll as #bufx
calldll #bufx,"ExeBasic", code$ as ptr, 0 as long,1 as long,result as long
'also you can get the value a variable
calldll #bufx,"GetValue", "VAR4#" as ptr, 0 as long,1 as long,result2 as Double
notice str$(result2)
'Or get the value of a string variable
variablex$="VARTEXT$"
text$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,text$ as ptr,result as long
notice "Result of VARTEXT$="+text$
CLOSE #bufx
Another code with LBB

Code: Select all

'Sample for Liberty Basic
'using EVAL.DLL and execute code from variables
'
'you can use this DLL passing code delimited with CHR$(13)+CHR$(10)
CRLF$ =chr$(13) +chr$(10)
sourcecode$="A#=100.42"+CRLF$+_
"B#=20.13"+CRLF$+_
"C#=A#+B#"+CRLF$+_
"MSGBOX C#,0,"+chr$(34)+"Result of EVAL"+chr$(34)+CRLF$+ _
"text$="+CHR$(34)+"My Name Is Israel"+chr$(34)+chr$(0)
sourcecode$=trim$(left$(sourcecode$,32767))
open "EVAL.DLL" for dll as #bufx
calldll #bufx,"ExeBasic", sourcecode$ as ptr, 0 as long,1 as long,result as long
calldll #bufx,"SetTextValue", "R$" as ptr,"This is a test" as ptr,1 as long,result as long
importe=1500.16
calldll #bufx,"SetValue", "R#" as ptr,1500.17 as double,1 as long,result as long
variablex$="text$"
resultado$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,resultado$ as ptr,result as long
print "text$="+trim$(left$(resultado$,255))
variable$="A#"
calldll #bufx,"GetValue", variable$ as ptr,valorA as double
print "A#=";valorA
variable$="B#"
calldll #bufx,"GetValue", variable$ as ptr,valorB as double
print "B#=";valorB
variable$="C#"
calldll #bufx,"GetValue",variable$ as ptr,valorC as double
print "C#=";valorC
result=valorC * 10
print "C#*10=";result
variablex$="R$"
resultado$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,resultado$ as ptr,result as long
print "Result of R$="+trim$(left$(resultado$,255))
variable$="R#"
calldll #bufx,"GetValue",variable$ as ptr,valorR as double
print valorR
calldll #bufx,"ExeBasic", "TestNUM1#=1200.25" as ptr, 0 as long,1 as long,result as long
calldll #bufx,"ExeBasic", "TestNUM2#=1401.18" as ptr, 0 as long,1 as long,result as long
calldll #bufx,"ExeBasic", "Total#=TestNum1#+testnum2#" as ptr, 0 as long,1 as long,result as long
calldll #bufx,"ExeBasic", "left4$=left$(text$,4)" as ptr, 0 as long,1 as long,result as long
calldll #bufx,"ExeBasic", "right4$=right$(text$,4)" as ptr, 0 as long,1 as long,result as long
calldll #bufx,"ExeBasic", "PARSE2$=PARSE$(text$,"+" Is "+",2)" as ptr, 0 as long,1 as long,result as long
variablex$="LEFT4$"
resultado$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,resultado$ as ptr,result as long
print "left4$="+trim$(left$(resultado$,255))
variablex$="RIGHT4$"
resultado$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,resultado$ as ptr,result as long
print "RIGHT4$="+trim$(left$(resultado$,255))
variablex$="PARSE2$"
resultado$=space$(255)+chr$(0)
calldll #bufx,"GetTextValue", variablex$ as ptr,resultado$ as ptr,result as long
print "PARSE2$="+trim$(left$(resultado$,255))
variable$="TOTAL#"
calldll #bufx,"GetValue", variable$ as ptr,Total as double
print "Total=";Total
EVAL v1.00 by Israel Vega Alvarez

EVAL is my tool for execute script or solve expression using variables. Variables only accept string or numbers. For string variables use the $ identifier, for numeric variables use the # identifier.

This tool have the next mainly functions for execute script:

ExeBasic()
SetValue()
SetTextValue()
GetValue()
GetTextValue()
SetMaxVariables()
SetMaxLines()

ExeBasic()
Execute script in Basic (only function and sentences documented in last page of this help).

Syntax: ExeBasic StringCode, Handle, Mode

Where StringCode is a variable with the code to execute, Handle may be set to 0 and is for future use. Mode may be set to 0 or 1 (0=initialize 1=preserve variables). If Mode is set to 0 then clear or initialize all in memory. If is set to 1 then preserve variables but initialize number of lines and buffers internally.

SetValue()
Set a value in a numeric variable.

Syntax: SetValue VarName, Value, Mode

VarName must be a variable name of numeric type. For example a name of numeric variable may be VARNUM#. Value must have the numeric value to set variable. Mode is for clear or preserve previous values of other variables.

SetTextValue()
Set a value in a string variable.

Syntax: SetTextValue VarName, stringValue, Mode

VarName must be a variable name of string type. For example a name of string variable may be VARNUM$. stringValue must have the value for set text variable. Mode is for clear or preserve previous variables.

GetValue()
Get value from a numeric variable.

Syntax: GetValue(VarName)
Return the value of a numeric variable. By example: RESULT=GetValue(“VARNUM#”)

GetTextValue()
Get value from a string variable.

Syntax: GetTextValue(VarName)
Return the value of a string variable. By example: RESULT$=GetTextValue(“VARNUM$”)

SetMaxVariables()
Syntax: SetMaxVariables maxvar
Allow set the max number of variables availables example: SetMaxVariables 1000


SetMaxLines()
Syntax: SetMaxLines maxlines
Allow set the max number of lines availables example: SetMaxLines 1000


The next list is all functions and sentences that is possible execute:

CLOSE #
DATEDIF()
EOF()
FIELD #
FORMAT$()
GET #
CLOSE #
DATEDIF()
EOF()
FIELD #
FORMAT$()
GET #
GETCLIPBOARDTEXT
GETFOCUS
GETTEXT
GOSUB
GOTO
IF()
INPUT #
LCASE$()
LEFT$()
LEN()
LINE INPUT #
LOF()
LSET$()
LTRIM$()
MCASE$()
MID$()
MSGBOX
NUMLETRA()
OPEN
PARSE$()
PRINT #
PUT #
RES_FECHA()
RETURN
RIGHT$()
RSET$()
RTRIM$()
SETCLIPBOARDTEXT
SETFOCUS
SETTEXT
STOP
STR$()
SUM_FECHA()
TRIM$()
UCASE$()
VAL()
WRITE #



Restriction:
It does not support nested functions, if you want to use a function you must run it separately.
THIS SOFTWARE CONTAINED HEREIN IS PROVIDED 'AS IS' AND COMES WITH NO WARRANTIES OF ANY KIND.
You do not have the required permissions to view the files attached to this post.
ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

Re: My EVAL for use with BBC BASIC

Post by ivega718 »

Now is working fine in BBC BASIC. After a long search I found this link:

http://bbcbasic.co.uk/wiki/doku.php?id= ... n_20floats

I like BBC BASIC. Its syntax is very easy to understand, I love it

Code: Select all

         TEXT$ = "" : variablex$ = "" : resultado$ = "" : variable$ = ""
      TEXT$ = "ESTA ES UNA PRUEBA and my name Is Israel"
      SYS "LoadLibrary", "EVAL.DLL" TO EVDLL%
      SYS "GetProcAddress", EVDLL%, "ExeBasic" TO ExeBasic%
      SYS "GetProcAddress", EVDLL%, "GetTextValue" TO GetTextValue%
      SYS "GetProcAddress", EVDLL%, "GetValue" TO GetValue%

      SYS ExeBasic%, "TestNUM1#=1200.25",0,1 TO result%
      SYS ExeBasic%, "TestNUM2#=1401.18", 0, 1 TO result%
      SYS ExeBasic%, "TEXT$=" + TEXT$, 0, 1 TO result%
      SYS ExeBasic%, "TOTAL#=TestNum1#+testnum2#", 0, 1 TO result%
      SYS ExeBasic%, "left4$=left$(text$,4)", 0, 1 TO result%
      SYS ExeBasic%, "PARSE2$=PARSE$(text$," + " Is " + ",2)", 0, 1 TO result%

      resultado$=STRING$(255," ")+CHR$(0)

      SYS GetTextValue%, "left4$", resultado$ TO result
      PRINT "LEFT4$="+resultado$

      SYS GetTextValue%, "PARSE2$",resultado$ TO result
      PRINT "PARSE2$=" + resultado$

      SYS FN_sysfloat(GetValue%, result#), "TOTAL#"
      PRINT result#
      END


      DEF FN_sysfloat(D%, RETURN R%)
      DIM R% LOCAL -1
      PRIVATE A%, C%, S%
      IF A%=D% IF S%=R%!20 THEN =C%
      LOCAL P%
      IF C%=0 DIM C% 26
      P% = C% : S% = R%!20 : A% = D%
      [OPT 2
      pop dword [S%]
      call D%
      push dword [S%]
      fld st0
      fstp qword [S%]
      ret
      ]
      =C%


ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

Re: My EVAL for use with BBC BASIC

Post by ivega718 »

This sample open a RANDOM file, put values and get values:

Code: Select all

      SYS "LoadLibrary", "EVAL.DLL" TO EVDLL%
      SYS "GetProcAddress", EVDLL%, "ExeBasic" TO ExeBasic%
      SYS "GetProcAddress", EVDLL%, "GetTextValue" TO GetTextValue%
      SYS ExeBasic%,"OPEN ARCHIVO.DAT FOR RANDOM AS #1 LEN=44",0,0 TO result%
      SYS ExeBasic%,"FIELD #1,4 AS CODIGO$,40 AS NAME$",0,1 TO result%
      SYS ExeBasic%, "CODIGO$="+"100",0,1 TO result%
      SYS ExeBasic%, "NAME$="+"ISRAEL VEGA ALVAREZ",0,1 TO result%
      SYS ExeBasic%, "PUT #1,1",0,1 TO result%
      SYS ExeBasic%, "CODIGO$="+"101",0,1 TO result%
      SYS ExeBasic%, "NAME$="+"JUAN PEREZ PEREZ",0,1 TO result%
      SYS ExeBasic%, "PUT #1,2",0,1 TO result%
      SYS ExeBasic%, "GET #1,1",0,1 TO result%
      SYS ExeBasic%, "MSGBOX CODIGO$",0,1 TO result%
      SYS ExeBasic%, "MSGBOX NAME$",0,1 TO result%
      SYS ExeBasic%, "GET #1,2",0,1 TO result%
      SYS ExeBasic%, "MSGBOX CODIGO$",0,1 TO result%
      SYS ExeBasic%, "MSGBOX NAME$",0,1 TO result%
      SYS ExeBasic%, "CLOSE #1",0,1 TO result%
      resultado$=STRING$(255," ")+CHR$(0)
      SYS GetTextValue%, "CODIGO$", resultado$ TO result
      PRINT "Value of last CODIGO$="+resultado$
      resultado$=STRING$(255," ")+CHR$(0)
      SYS GetTextValue%, "NAME$", resultado$ TO result
      PRINT "Value of last NAME$="+resultado$

      SYS "FreeLibrary", EVDLL%


DDRM

Re: My EVAL for use with BBC BASIC

Post by DDRM »

Hi Israel,

I'm not quite sure what your routines are doing, and I'm reluctant to be importing unknown code into an environment where it could potentially do a lot of damage...

Could you tell us a bit more about your DLLs and the routines?

It looks a bit as though you are using BB4W as a shell to run your own implementation of BASIC, and some system functions you could use directly from BB4W? Or am I misunderstanding what you are trying to achieve?

Best wishes,

D
ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

Re: My EVAL for use with BBC BASIC

Post by ivega718 »

My DLL is a set of functions and statements to evaluate variables in runtime. There is no malicious code, it is safe. I know that EVAL from BBC BASIC can also do many things and I love it. Only sometimes I also need to expand the set of functions in my case. It's just another way to run an EVAL. I'm getting to know BBC BASIC.

Code: Select all

      C=20
      A = EVAL("C+4")
      dummy = EVAL("FNassign(RESULT, A*2)")
      PRINT RESULT


      PRUEBA$="ISRAEL"
      DATO$=EVAL("LEFT$(PRUEBA$,3)")
      B$=EVAL("FNassignSTRING(RESULTADO$,DATO$)")
      PRINT RESULTADO$

      X=EVAL("OPENOUT "+CHR$(34)+"C:\BBCBASIC\PRUEBAX.DAT"+CHR$(34))

      DEF FNassign(RETURN n, v) : n = v : = 0
      DEF FNassignSTRING(RETURN nx$, vx$) : nx$ = vx$ : = ""

Yes, I can see that it can also be done in BBC BASIC. It is wonderful. I am exploring and I see that even sentences can be executed, not just variables. It's wonderful and I definitely do not need to use my EVAL.
DDRM

Re: My EVAL for use with BBC BASIC

Post by DDRM »

I'm sure you ARE being honest in saying the code isn't malicious, but if you were trying to sneak malicious code onto other people's machines you might not be honest! ;-)

Looking briefly at the code, you don't need to use EVAL in many of these circumstances: just use the functions themselves. So for example where you write
DATO$=EVAL("LEFT$(PRUEBA$,3)")
B$=EVAL("FNassignSTRING(RESULTADO$,DATO$)")

You can simply write

DATO$=LEFT$(PRUEBA$,3)
B$=FNassignSTRING(RESULTADO$,DATO$)

Where you want to call specialised routines from your DLL, you could also simply load the DLL, and then call the routines directly using SYS. I assume the routines are written in compiled C or something, so that may be quicker (and avoid rewriting time) than re-implementing them in BASIC.

Best wishes,

D
ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

Re: My EVAL for use with BBC BASIC

Post by ivega718 »

Because I need execute code that is inside of a textbox (edit) for formulas in payroll, for my is need do in this form.

Thank you for help me.

I am new using BBC BASIC and I have found a great compiler/interpreter that It is useful for many functions.

Best regards.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: My EVAL for use with BBC BASIC

Post by KenDown »

Hmmm. It depends on what you mean by "formulas in payroll".

If you have a Windows text box the standard way to read that box is

Code: Select all

SYS"GetDlgItemText".!winhandle%,iconnumber%,buffer%,buffersize%
pay$=$$buffer%
What happens next depends on the contents of a$. If it is "26.70" (for example), then all you need instead of the second line above is
pay=VAL$$buffer%

Only if it is a formula such as "26.70*4" would you need to use EVAL
ivega718
Posts: 15
Joined: Fri 15 Jun 2018, 20:28

Re: My EVAL for use with BBC BASIC

Post by ivega718 »

That is exactly the case. In a payroll system there are payments that can be calculated in different ways. That is why an expression evaluator is necessary.