AEChadwick Posted April 18, 2012 Share Posted April 18, 2012 Is there a simple way to determine if a number is odd or even? PASCAL math commands include ODD(x), but this appears missing from Vectorscript. I tried ODD anyway, and got this error. [font:Courier New] if ODD(wLights) then [do some stuff based on wLights]; | { Error: Identifier not declared. } | { Error: Expected a string. } | { Error: Expected a Boolean. } | { Error: Did not expect this after end of statement - missing ;? } [/font] (wLights is declared, I think the error is asking about "ODD") Alternately, is there perhaps a way to determine factors? I could simply check if a number is divisible by 2 or 3... I might be missing something obvious, but I have honestly been scouring the language guide and the developer reference. I appreciate any ideas! Quote Link to comment
michaelk Posted April 18, 2012 Share Posted April 18, 2012 Have you tried Test := X MOD 2; IF Test = 0 THEN {do even number stuff} ELSE {do odd numbered stuff} mk Quote Link to comment
AEChadwick Posted April 18, 2012 Author Share Posted April 18, 2012 I have not! because I do not recognize that command, X MOD 2; I can't find that in the guide... may I trouble you foe either a link or an explanation? Thanks! Quote Link to comment
JBenghiat Posted April 18, 2012 Share Posted April 18, 2012 mod is technically an operator, and a common programming method: http://en.wikipedia.org/wiki/Modulo_operation Quote Link to comment
AEChadwick Posted April 18, 2012 Author Share Posted April 18, 2012 Boom! perfect. Thank you both very much! (just had to make sure wLights was INTEGER... MOD won't take REAL.) [font:Courier New]Test := wLights MOD 2; IF Test = 0 THEN begin {do even number stuff} end ELSE begin {do odd numbered stuff} end; [/font] Quote Link to comment
Pat Stanford Posted April 19, 2012 Share Posted April 19, 2012 Just for future reference, all of the Operators (mathematical and boolean) are described in the Vectorscript Language Guide that is part of the VW Help. That information should probably also be in either the Function Reference or the Appendices. Quote Link to comment
AEChadwick Posted April 19, 2012 Author Share Posted April 19, 2012 Excellent point, Mr Stanford, but I must confess I would not have known to look for MOD regardless of its presence. When I post, it is as much for programming advice as for bibliographic reference?I apologize if that is a misuse of the forum. ? Quote Link to comment
Pat Stanford Posted April 19, 2012 Share Posted April 19, 2012 AE, Perfectly legitimate use of the forum. I posted this for my reference as much as yours. I have spent many hours looking in the Function Reference before remembering it is considered an "Operator" rather than a "Function" or "Procedure". I have filed an enhancement request to get it all pulled together in one place. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.