We help IT Professionals succeed at work.

# Rotating Values, some type of .net object rotator?

Hepen asked
on
Medium Priority
284 Views
Last Modified: 2010-04-23
I need some kind of .net object or something that will rotate values for me on a day to day basis.

State List
-----------
CA
PA
VA
NY
WA

So today would be CA, tommorow would be PA, the next day would be VA, the next day NY, the next day WA, then it would start from CA again.

Make sense?  I just need to be able to retrieve the value on a day to day basis in VB.net code.
Comment
Watch Question

## View Solution Only

Top Expert 2006

Commented:
Hi,

What I would do is have a start date and work out what you wanted to have shown on that date,

I'd then create an array with each of the states in it.

I'd then use

Dim d1 As Date = DateTime.Now
Dim d2 As Date = #Start Date#
Dim days As Integer = d2.Subtract(d1).Days

and then use days mod number of elements in array to get an integer - which then you can pull that element of the array

ie if days = 12 and there are 5 elements in the array then

then

12  mod 5 = 2

and then you would pull the element from the array [2]

this will always cycle through your elements in order depending on the day

Commented:
Hmm I grasp what you are saying. Could you specify just a little more clarity code wise?
CERTIFIED EXPERT
Commented:
Here is the code for rotate values. Queue(of T) only work with .NET 2.0. User Ctype for .NET 1.x

Module Module1

Sub Main()

For i As Integer = 1 To 15
Console.WriteLine(State.GetLatestState)
Next

Console.ReadLine()

End Sub

End Module

Public Class State

Private Shared _stateList As String() = {"CA", "PA", "VA", "NY", "WA"}
Private Shared _objQueue As New Queue(Of String)

Public Shared Function GetLatestState()

If _objQueue.Count = 0 Then
For Each lState As String In _stateList
_objQueue.Enqueue(lState)
Next
End If

Return _objQueue.Dequeue

End Function

End Class

Output

CA
PA
VA
NY
WA
CA
PA
VA
NY
WA
CA
PA
VA
NY
WA

Not the solution you were looking for? Getting a personalized solution is easy.

Access more of Experts Exchange with a free account
##### Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the