Solved

Rotating Values, some type of .net object rotator?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now