Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
AEChadwick

Is there a simple method to determine Odd/Even Integers?

Recommended Posts

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!

Share this post


Link to post

Have you tried

Test := X MOD 2;

IF Test = 0

THEN {do even number stuff}

ELSE {do odd numbered stuff}

mk

Share this post


Link to post

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!

Share this post


Link to post

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]

Share this post


Link to post

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.

Share this post


Link to post

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.

?

Share this post


Link to post

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.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×