Solved

Rotating Values, some type of .net object rotator?

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

20 Experts available now in Live!

Get 1:1 Help Now