ive already made a scripting language that can easily incorporate any db command...the only problem is getting variables and stuff like
variable = var1 * 2 + var3
Not that hard, actually. First write a replace string function and run this function through the expression, replacing variable names with values. You then have to solve the expression, and that's the hard bit. This code might help:
Dark basic v1 only, it used to work but I don't have it installed so I can't tell you:
rem Graph maker by cyberluke
dim var#(100)
dim var$(100)
sync on
sync rate 0
cls rgb(100,100,100)
eq$ = "2*(7*2)"
print Calculate(eq$)
wait key
x=0
y=0
ink rgb(0,0,255),0
do
c$=""
ink 0,0
box 0,0,200,20
ink rgb(0,0,255),0
line 0,240,639,240
line 320,0,320,479
set cursor 0,0
b$=a$
c$=inkey$()
if keystate(14)=1 then a$=left$(a$,len(a$)-1);c$=""
if returnkey()=1 then c$=""
a$=a$+c$
input "eq: ",a$
input "eq: ",b$
draw function(a$)
draw function(b$)
if returnkey()=1 then draw function(b$)
if c$<>"" then wait 100
sync
loop
function draw function(a$)
cls
x=-320
print "INPUT:",a$
line 0,240,639,240
line 320,0,320,479
oldx=-320
oldy=(0-function(a$,x,"x"))+240
ink rgb(0,255,0),0
for x=-320 to 320 step 5
y=(0-function(a$,x,"x"))+240
line x+320,y,oldx+320,oldy
oldx=x
oldy=y
sync
next x
endfunction
function compile(s$)
s#=0
oper=1
s$=remove all(s$," ")
if left$(s$,6)="delete"
var$=right$(s$,len(s$)-6)
delete var(var$)
oper=0
endif
if left$(s$,3)="box"
x1=Instr(0,s$,",")
x2=Instr(x1,s$,",")
x3=Instr(x2,s$,",")
x4=Instr(x3,s$,",")
endif
if oper=1
s#=equation(s$)
endif
endfunction s#
function function(s$,x,x$)
n=next free var()
var#(n)=x
var$(n)=x$
e#=val(Calculate(s$))
var#(n)=0
var$(n)=""
endfunction e#
function Equation(s$)
s$=remove all(s$," ")
num#=0
var$=""
value$=""
equal_sign=0
for i=1 to len(s$)
if mid$(s$,i)="=" then equal_sign=i
next i
if equal_sign>0
value$=Calculate(right$(s$,len(s$)-equal_sign))
`if val(value$)=0
var$=left$(s$,equal_sign-1)
found=0-10
for i=1 to 100
`found=find var(var$)
if var$(i)=var$ then found=i
next i
if found=0-10 then found=next free var();var$(found)=var$
var#(found)=val(value$)
endif
endfunction num#
function Calculate(line$)
line$=line$+"+0"
If CountChar(line$,"(") Or CountChar(line$,")")
`loop until no brackets
temp$="("
temp2$=")"
amount=CountChar(line$,temp$)
`print
`print amount
for k=1 to amount
res = 0
rec = 0
recpos = 0
recend = 0
endpos = 0
counter = 0
exec$=""
`//Fetch highest brackets and its position
For i = 1 To Len(line$)
If mid$(line$, i) = temp$ Then counter = counter + 1
If counter > rec Then rec = counter: recpos = i
If mid$(line$, i) = temp2$ Then counter = counter - 1
Next i
`//Fetch the end position of the highest brackets
endpos = InStr(recpos,line$,temp2$)
`//Fetch the contents of the highest brackets
recend=endpos
exec$ = mid2(line$,recpos+1, (endpos-recpos)-1)
exec$ = calc(exec$)
`//comprise result into a line and remove those brackets
line$ = left$(line$, recpos - 1) + exec$ + right$(line$, Len(line$) - endpos)
`print left$(line$,len(line$)-2)
next k
Else
`// no brackets here
line$ = calc(line$)
EndIf
line$ = calc(line$)
line$ = calc(line$)
endfunction line$
function CountChar(Variable$,FindChar$)
CountChar = 0
For i = 1 To Len(Variable$)
If Mid$(Variable$, i) = FindChar$ Then CountChar = CountChar + 1
Next i
endfunction CountChar
function mid2(line$,start,leng)
a$=""
if start<1 then start=1
endv=start+leng-1
start=start-1
a$=right$(left$(line$,endv),endv-start)
endfunction a$
function Instr(start,line$,find$)
a=0
for i=start to len(line$)-len(find$)
if mid2(line$,i,len(find$))=find$ then a=i:goto endf
next i
endf:
endfunction a
function calc(s$)
`DIM arrays
dim oper$(20):dim word$(20):dim word#(20)
for i=1 to 20
oper$(i)=""
word$(i)=""
word#(i)=0
next i
e=1
for i=1 to LEN(s$)
if mid$(s$,i)="+" then oper$(e)="+";inc e;goto next_i
if mid$(s$,i)="-"
oper$(e)="-"
inc e
if mid$(s$,i+1)="-" then word$(e)="-";inc i
if mid$(s$,i+1)="+" then inc i
goto next_i
endif
if mid$(s$,i)="*"
oper$(e)="*"
inc e
if mid$(s$,i+1)="-" then word$(e)="-";inc i
goto next_i
endif
if mid$(s$,i)="/"
oper$(e)="/"
inc e
if mid$(s$,i+1)="-" then word$(e)="-";inc i
goto next_i
endif
if mid$(s$,i)="^" or lower$(mid$(s$,i))="e"
oper$(e)="^"
inc e
if mid$(s$,i+1)="-" then word$(e)="-";inc i
goto next_i
endif
` if mid$(s$,i)="(" then oper$(e)="(";inc e;goto next_i
` if mid$(s$,i)=")" then oper$(e)=")";inc e;goto next_i
if lower$(mid2(s$,i,4))="sqrt" then oper$(e)="^";inc e;inc i,4;word$(e)="0.5";inc e;goto next_i
word$(e)=word$(e)+mid$(s$,i)
next_i:
next i
`Convert strings to numbers
for i=1 to 20
if word$(i)="pi" then word$(i)="3.1415926535897932384626433832795"
next i
for i=1 to 20
word#(i)=val(word$(i))
if val(word$(i))=0
v=find var(word$(i))
word#(i)=var#(v)
v=0
endif
next i
oper$(0)="+":result#=0:c=0:d=-1:f=-1:a=1:g=1:max20=19
`Solve ^ first
for i=1 to 20:word$(i)=str$(word#(i)):next i
for o=1 to 20:for p=1 to 20:word$(p)=str$(word#(p)):next p:for i=1 to 20
if oper$(i-1)="^" and word$(i)<>"":word#(i-1)=word#(i-1)^word#(i):word#(i)=0:word$(i)=str$(word#(i))
for e=i+d to max20 step 1:oper$(e)=oper$(e+a):next e
for e=i+c to max20 step 1:word#(e)=word#(e+a):word$(e)=str$(word#(e+a)):next e
inc i,f:goto calculator_exit_1:endif
next i
calculator_exit_1:
next o
`Then solve * and /
for o=1 to 20:for i=1 to 20
if oper$(i-1)="*" and word$(i)<>"":word#(i-1)=word#(i-1)*word#(i):word#(i)=0:word$(i)=str$(word#(i))
for e=i+d to max20 step 1:oper$(e)=oper$(e+a):next e
for e=i+c to max20 step 1:word#(e)=word#(e+a):word$(e)=str$(word#(e+a)):next e
inc i,f:goto calculator_exit_2:endif
if oper$(i-1)="/" and word#(i)<>0:word#(i-1)=word#(i-1)/word#(i):word#(i)=0:word$(i)=str$(word#(i))
for e=i+d to max20 step 1:oper$(e)=oper$(e+a):next e
for e=i+c to max20 step 1:word#(e)=word#(e+a):word$(e)=str$(word#(e+a)):next e
inc i,f:goto calculator_exit_2:endif
next i
calculator_exit_2:
next o
for i=1 to 20:word$(i)=str$(word#(i)):next i
`finally solve + and -
for i=1 to 20
if oper$(i-1)="+" then result#=result#+val(word$(i))
if oper$(i-1)="-" then result#=result#-val(word$(i))
next i
result$=str$(result#)
undim oper$():undim word$():undim word#()
endfunction result$
function next free var()
n=0
for i=1 to 100
if var$(i)="" then n=i;goto endf
next i
endf:
endfunction n
function find var(s$)
n=0
for i=1 to 100
if var$(i)=s$ then n=i;goto endf
next i
endf:
endfunction n
function delete var(s$)
for i=1 to 100
if var$(i)=s$ then var$(i)="";var#(i)=0
next i
endfunction
function remove all(s$,d$)
d=len(d$)
s=len(s$)
a=CountChar(s$,d$)
for i=1 to len(s$)-d
if mid2(s$,i,d)=d$
s$=left$(s$,i-1)+right$(s$,(len(s$)-i)+(d-1))
dec i,1
endif
next i
endfunction s$
However, I want to try and use the microsoft scripting engine expression solver to my advantage - I wonder if I can tie it into db?
You are the
th person to view this signature.
GRAVITY: I fought the law but the law won