Solved

Rotating Values, some type of .net object rotator?

Posted on 2006-10-31
6
255 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.
0
Comment
Question by:Hepen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17845782
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
0
 

Author Comment

by:Hepen
ID: 17846312
Hmm I grasp what you are saying. Could you specify just a little more clarity code wise?
0
 
LVL 10

Accepted Solution

by:
ericwong27 earned 500 total points
ID: 17847779
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
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question