forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Anyone know if theres a Multiply Function?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Thu Feb 19, 2004 5:39 am    Post subject: Reply with quote

Cool
_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
Serge
Professional Member
Professional Member


Joined: 04 Mar 2002
Posts: 1480
Location: Australia

PostPosted: Thu Feb 19, 2004 12:14 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 4:28 pm    Post subject: Reply with quote

It will do the right calculations... Wink I had to think about it a little while, but than I came up with a way with which it is just right... Smile When I release it (I hope today, yesterday my little brother shut the computer down when I was a few moments away... Sad) I'll also make a little example in which order the calculations are done. Please correct me then if I forgot something. Smile
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Thu Feb 19, 2004 4:34 pm    Post subject: Reply with quote

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. Wink

Cheers, Mac Smile

_________________
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
View user's profile Send private message Send e-mail
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 4:38 pm    Post subject: Reply with quote

It already supports that... Wink But it also has to do 'normal' calculations properly, like "1+2*4". I believe it already is doing that (first *, than /, than + and then -), but I don't really know for sure... Sad
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 4:55 pm    Post subject: Reply with quote

Droolll..... Waiting ....still waiting... hehe.. Twisted Evil
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 6:18 pm    Post subject: Reply with quote

Here it is already... Smile 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
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 6:33 pm    Post subject: Reply with quote

GREAT!!! Worship Thanks so much! This rocks. Very Happy
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 6:36 pm    Post subject: Reply with quote

Now, a little error checking to make sure numbers are used, it'll be perfect. Wink I'd do it, but, I'm a little busy.
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 6:38 pm    Post subject: Reply with quote

What do you mean exactly? That if people use @calculate(1+2+A), that it will give an error?
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 6:41 pm    Post subject: Reply with quote

yeah. I got an error when i did it.
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 6:43 pm    Post subject: Reply with quote

That's what you wanted, wasn't it? Rolling Eyes
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 6:47 pm    Post subject: Reply with quote

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.. Laughing
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Skit3000
Admin Team


Joined: 11 May 2002
Posts: 2166
Location: The Netherlands

PostPosted: Thu Feb 19, 2004 6:49 pm    Post subject: Reply with quote

Can you give me an example error ? Laughing
_________________
[ Add autocomplete functionality to your VDS IDE windows! ]
Voor Nederlandse beginners met VDS: bekijk ook eens deze tutorial!
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1754
Location: Space and Time

PostPosted: Thu Feb 19, 2004 6:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group