| View previous topic :: View next topic |
| Author |
Message |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Thu Feb 19, 2004 5:39 am Post subject: |
|
|
 _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Thu Feb 19, 2004 12:14 pm Post subject: |
|
|
skit,
will your dsu do proper maths like 1+2x4=9 or will it do "mickey mouse" maths like 1+2x4=12?
sorry...i guess that it is the maths teacher in me that is coming out...
serge _________________
|
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Thu Feb 19, 2004 4:28 pm Post subject: |
|
|
It will do the right calculations... I had to think about it a little while, but than I came up with a way with which it is just right... When I release it (I hope today, yesterday my little brother shut the computer down when I was a few moments away... ) I'll also make a little example in which order the calculations are done. Please correct me then if I forgot something.  _________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial! |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Feb 19, 2004 4:34 pm Post subject: |
|
|
Seems it would be more versatile for programming
if you allow the user to group the order of calculation
(as LiquidCode suggested):
@math([1 + 2] x 4) OR @math(1+ [2 x 4])
Just my opinion.
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 4:55 pm Post subject: |
|
|
Droolll..... Waiting ....still waiting... hehe..  _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Thu Feb 19, 2004 6:18 pm Post subject: |
|
|
Here it is already... Here is a little table with operations you can use:
| Code: | Operation Sign
Brackets ( and ) or [ and ]
Product * or x
Division / or :
Sum +
Difference - |
The script will first execute the calculation between brackets (the most nested first) by just calling the @calculate() function itself. It will then replace the returning value in the input value, after which a 'normal' calculation will stay behind. Than, it will just execute that, by first doing products, than divisions, than sums and then the difference.
| Code: | #define function,calculate
info "1 + 2 x 4 = "@calculate("1 + 2 x 4")
info "(1 + 2) x 4 = "@calculate("(1 + 2) x 4")
exit
:Calculate
if @greater(@pos(A,%1),0)@greater(@pos(B,%1),0)@greater(@pos(C,%1),0)@greater(@pos(D,%1),0)@greater(@pos(E,%1),0)@greater(@pos(F,%1),0)@greater(@pos(G,%1),0)@greater(@pos(H,%1),0)@greater(@pos(I,%1),0)@greater(@pos(J,%1),0)@greater(@pos(K,%1),0)@greater(@pos(L,%1),0)@greater(@pos(M,%1),0)@greater(@pos(N,%1),0)@greater(@pos(O,%1),0)@greater(@pos(P,%1),0)@greater(@pos(Q,%1),0)@greater(@pos(R,%1),0)@greater(@pos(S,%1),0)@greater(@pos(T,%1),0)@greater(@pos(U,%1),0)@greater(@pos(V,%1),0)@greater(@pos(W,%1),0)@greater(@pos(Y,%1),0)
if @unequal(@substr(%1,1,1),"M")
exit
end
end
# Replace ( and ) with [ and ]
while @greater(@pos("(",%1),0)
if @equal(@pos("(",%1),1)
%1 = "["@substr(%1,@succ(@pos("(",%1)),@len(%1))
else
%1 = @substr(%1,1,@pred(@pos("(",%1)))"["@substr(%1,@succ(@pos("(",%1)),@len(%1))
end
wend
while @greater(@pos(")",%1),0)
%1 = @substr(%1,1,@pred(@pos(")",%1)))"]"@substr(%1,@succ(@pos(")",%1)),@len(%1))
wend
# Replace some characters into the 'official' characters, like 'x' to '*', etc.
while @greater(@pos("x",%1),0)
%1 = @substr(%1,1,@pred(@pos("x",%1)))"*"@substr(%1,@succ(@pos("x",%1)),@len(%1))
wend
while @greater(@pos(":",%1),0)
%1 = @substr(%1,1,@pred(@pos(":",%1)))"/"@substr(%1,@succ(@pos(":",%1)),@len(%1))
wend
# Remove spaces
while @greater(@pos(" ",%1),0)
%1 = @substr(%1,1,@pred(@pos(" ",%1)))@substr(%1,@succ(@pos(" ",%1)),@len(%1))
wend
while @greater(@pos("]",%1),0)
%%Bracket1 = @pos("]",%1)
%%Bracket2 = %%Bracket1
while @unequal(@substr(%1,%%Bracket2,%%Bracket2),"[")
%%Bracket2 = @pred(%%Bracket2)
wend
%%BracketCalculation = @substr(%1,@succ(%%Bracket2),@pred(%%Bracket1))
%%BracketTemp = @calculate(%%BracketCalculation)
if @equal(%%Bracket2,1)
%1 = %%BracketTemp@substr(%1,@succ(%%Bracket1),@len(%1))
else
%1 = @substr(%1,1,@pred(%%Bracket2))%%BracketTemp@substr(%1,@succ(%%Bracket1),@len(%1))
end
wend
while @greater(@pos("--",%1),0)
if @equal(@pos("--",%1),1)
%1 = @substr(%1,3,@len(%3))
else
%1 = @substr(%1,1,@pred(@pos("--",%1)))+@substr(%1,@fadd(@pos("--",%1),2),@len(%1))
end
wend
# --- PRODUCT ---
while @greater(@pos("*",%1),0)
%%Product1 = @pos("*",%1)
%%Product2 = @pred(%%Product1)
%%Product3 = @succ(%%Product1)
while @numeric(@substr(%1,%%Product2,%%Product2))
%%Product2 = @pred(%%Product2)
wend
%%Product2 = @succ(%%Product2)
if @equal(@substr(%1,%%Product3,%%Product3),"-")
%%Product3 = @succ(%%Product3)
end
while @numeric(@substr(%1,%%Product3,%%Product3))
%%Product3 = @succ(%%Product3)
wend
%%Product3 = @pred(%%Product3)
%%ProductNumber1 = @substr(%1,%%Product2,@pred(%%Product1))
%%ProductNumber2 = @substr(%1,@succ(%%Product1),%%Product3)
%%ProductNumber = @fmul(%%ProductNumber1,%%ProductNumber2)
if @equal(%%Product2,1)
%1 = %%ProductNumber@substr(%1,@succ(%%Product3),@len(%1))
else
%1 = @substr(%1,1,@pred(%%Product2))%%ProductNumber@substr(%1,@succ(%%Product3),@len(%1))
end
wend
# --- DIVISION ---
while @greater(@pos("/",%1),0)
%%Division1 = @pos("/",%1)
%%Division2 = @pred(%%Division1)
%%Division3 = @succ(%%Division1)
while @numeric(@substr(%1,%%Division2,%%Division2))
%%Division2 = @pred(%%Division2)
wend
%%Division2 = @succ(%%Division2)
if @equal(@substr(%1,%%Division3,%%Division3),"-")
%%Division3 = @succ(%%Division3)
end
while @numeric(@substr(%1,%%Division3,%%Division3))
%%Division3 = @succ(%%Division3)
wend
%%Division3 = @pred(%%Division3)
%%DivisionNumber1 = @substr(%1,%%Division2,@pred(%%Division1))
%%DivisionNumber2 = @substr(%1,@succ(%%Division1),%%Division3)
%%DivisionNumber = @fdiv(%%DivisionNumber1,%%DivisionNumber2)
if @equal(%%Division2,1)
%1 = %%DivisionNumber@substr(%1,@succ(%%Division3),@len(%1))
else
%1 = @substr(%1,1,@pred(%%Division2))%%DivisionNumber@substr(%1,@succ(%%Division3),@len(%1))
end
wend
# --- SUM ---
while @greater(@pos("+",%1),0)
%%Sum1 = @pos("+",%1)
%%Sum2 = @pred(%%Sum1)
%%Sum3 = @succ(%%Sum1)
while @numeric(@substr(%1,%%Sum2,%%Sum2))
%%Sum2 = @pred(%%Sum2)
wend
%%Sum2 = @succ(%%Sum2)
if @equal(@substr(%1,%%Sum3,%%Sum3),"-")
%%Sum3 = @succ(%%Sum3)
end
while @numeric(@substr(%1,%%Sum3,%%Sum3))
%%Sum3 = @succ(%%Sum3)
wend
%%Sum3 = @pred(%%Sum3)
%%SumNumber1 = @substr(%1,%%Sum2,@pred(%%Sum1))
%%SumNumber2 = @substr(%1,@succ(%%Sum1),%%Sum3)
%%SumNumber = @fadd(%%SumNumber1,%%SumNumber2)
if @equal(%%Sum2,1)
%1 = %%SumNumber@substr(%1,@succ(%%Sum3),@len(%1))
else
%1 = @substr(%1,1,@pred(%%Sum2))%%SumNumber@substr(%1,@succ(%%Sum3),@len(%1))
end
wend
# --- DIFFERENCE ---
while @greater(@pos("-",%1),0)
%%Difference1 = @pos("-",%1)
%%Difference2 = @pred(%%Difference1)
%%Difference3 = @succ(%%Difference1)
if @equal(@substr(%1,1,1),"-")
%1 = M@substr(%1,2,@len(%1))
end
while @numeric(@substr(%1,%%Difference2,%%Difference2))
%%Difference2 = @pred(%%Difference2)
wend
%%Difference2 = @succ(%%Difference2)
while @numeric(@substr(%1,%%Difference3,%%Difference3))
%%Difference3 = @succ(%%Difference3)
wend
%%Difference3 = @pred(%%Difference3)
%%DifferenceNumber1 = @substr(%1,%%Difference2,@pred(%%Difference1))
%%DifferenceNumber2 = @substr(%1,@succ(%%Difference1),%%Difference3)
if @equal(%%DifferenceNumber1,"M")
%%DifferenceNumber = M%%DifferenceNumber2
else
%%DifferenceNumber = @fsub(%%DifferenceNumber1,%%DifferenceNumber2)
end
if @equal(%%Difference2,1)
%1 = %%DifferenceNumber@substr(%1,@succ(%%Difference3),@len(%1))
else
%1 = @substr(%1,1,@pred(%%Difference2))%%DifferenceNumber@substr(%1,@succ(%%Difference3),@len(%1))
end
wend
if @equal(@substr(%1,1,1),"M")
%1 = "-"@substr(%1,2,@len(%1))
end
exit %1 |
_________________ [ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Last edited by Skit3000 on Thu Feb 19, 2004 7:09 pm; edited 3 times in total |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 6:33 pm Post subject: |
|
|
GREAT!!! Thanks so much! This rocks.  _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 6:36 pm Post subject: |
|
|
Now, a little error checking to make sure numbers are used, it'll be perfect. I'd do it, but, I'm a little busy. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 6:41 pm Post subject: |
|
|
yeah. I got an error when i did it. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 6:47 pm Post subject: |
|
|
It works great and as it should, I just want a little error checking. If the numbers don't calculate right, I don't want it to choke. I'm not bashing your code, as I said it's great. That is what I wanted. I'm just pickey..  _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1754 Location: Space and Time
|
Posted: Thu Feb 19, 2004 6:53 pm Post subject: |
|
|
Try these:
| Code: |
info @calculate("100+3/120*123456789")
info @calculate("100+3.c")
|
I know that they are not supposed to work, so I just want it to return null. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|