Solved

Rotating Values, some type of .net object rotator?

Posted on 2006-10-31
6
247 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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