## 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

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\2b=7mod2Msgbox aMsgbox 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 thenmsgbox "a is a prime number"end ifend if` Lyberodoggy
Administrator

Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

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!

Thanks  Lyberodoggy
Administrator

Posts: 2519
Joined: Sat Feb 17, 2007 3:31 pm
Location: Athens

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 1 guest 