Page 1 of 1

What is "Mod" in PB? *solved*

Posted: Fri Mar 02, 2007 9:45 am
by CadeX
http://www.microsoft.com/technet/script ... y1019.mspx

As described in there (no, i am not Jo) i'm trying to work with odd and even numbers. If anyone knows another alternative, do tell!

Thanks for reading.

Posted: Fri Mar 02, 2007 9:50 am
by Kale

Code: Select all

NumberToTest.l = 15
NumberToTest % 2
% = Mod (Modulo)

http://www.purearea.net/pb/english/manu ... ables.html
scroll to the bottom.

Posted: Fri Mar 02, 2007 9:51 am
by CadeX
Thankyou very much!

Re: What is "Mod" in PB? *solved*

Posted: Fri Mar 02, 2007 9:52 am
by PB
Use % where you see Mod in other Basics. So, for the URL you quoted, do this:

Code: Select all

a = 13

intResult = a % 2

If intResult = 0
    Debug "This is an even number."
ElseIf intResult = 1
    Debug "This is an odd number."
Else
    Debug "This does not appear to be a whole number."
EndIf

Posted: Fri Mar 02, 2007 1:58 pm
by Kaeru Gaman
hint:

% is quite slow.
since this all is about Integers, you can also test bit 0 to determine odd or even:

Code: Select all

Odd = Value & 1
Demo:

Code: Select all

For attepts = 1 To 100
  Value = Random(999999999)-500000000
; ****  
  Odd = Value & 1
; ****  
  If Odd
    Gen$ = "odd"
  Else
    Gen$ = "even"
  EndIf
  Debug Str(Value) +" is "+Gen$
Next