C# - 15 - Cyclic integers

[C# 2.0]

The book "MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0" offers a potentially useful struct/class called Cycle. The purpose of Cycle was to store an integer value that had a cyclic range of values. This could be month number, week number, degrees in a circle, or whatever.

Unfortunately as presented in the book it has a number of flaws and shortcomings. Here is a modified version for your use. Add a class module to your project and copy the code in. An explanation on how to use it is down the bottom.

Okay. So how do you use it?

The first line of this code creates a Cycle variable called quarters with a range of 1 to 4 and initialises it to 1 (the minimum value). The rest of the code overrides this value to 2, then adds 2 three times and subtracts 1. The final result (3) is displayed.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License