Division

This forum is meant for people to share their knowledge by writing their own tutorials for Adventure Maker.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Division

Postby Lyberodoggy » Wed Jul 22, 2009 12:43 am

Did you know that vbs offers one more pair of division operators?
They are the integer division operator (\) and the modulus division operator (mod)

Examples of usage:
Code: Select all
a=7\2
b=7mod2
Msgbox a
Msgbox b


Now "a" is going to store the value "3", because the integer deriving from the 7/2 division is 3 and "b" is going to store the value "1", because the modulus of 7/2 is 1

It all comes from euclidean division, Euclides mathematical model of division:
a=b*a\b+amodb

The practical uses of these operators are many in programming. One common use is this:
Code: Select all
If amod2=0 then
msgbox "a is not a prime number"
else if amod2=1 then
msgbox "a is a prime number"
end if
end if
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby Chromegloss55 » Sun Aug 23, 2009 5:17 am

A more simple way to explain the mod function is this:

Code: Select all
AModB


Where A and B are both numbers. The Mod function divides A by B and returns the remainder. That's the simplest way of putting it.

The Mod function equates to either of these two functions:

Code: Select all
A - (B * fix(A/B))

A - (B * (A\B))


The fix function removes the fraction from a number. Dunno if it works in AM, but it's another useful little tip. If fix doesn't work, then simply use:

Code: Select all
Sign (X) * Int(Abs(X))


Where X is the number or expression in question, in this case A/B.
Chromegloss - Vanishes and then re-appears at complete random. [Working on Advanced Section of VBScript guide]
Chromegloss55
Forum Master
 
Posts: 630
Joined: Sat Nov 03, 2007 2:49 pm
Location: God Knows!

Postby Lyberodoggy » Mon Aug 24, 2009 7:27 pm

Thanks :)
User avatar
Lyberodoggy
Administrator
 
Posts: 2526
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

Postby juhuwoorps » Mon Aug 24, 2009 8:05 pm

Thanks! :) :)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm


Return to Post Your Own Tutorials

Who is online

Users browsing this forum: No registered users and 0 guests

cron