Solved

Rotating Values, some type of .net object rotator?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help using System.Web.HttpUtility.HtmlEncode in my VB.Net application 3 74
Put window Form inside tab page 10 33
Exit the loop 4 42
cannot connect to sqlserver 8 25
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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