On Thu, Jul 15, 2010 at 9:27 AM, Shipley, Peter G.
<Peter.Shipley@xxxxxxxxxx> wrote:
Hello Everyone,



I have been given the task of rewriting a Visual RPG Shop Floor system in VB.Net.



Would anyone be able to advise me on how I can use an Array to lookup a date in VB.Net?


Peter,

( VB instead of C# ?)

the .net framework way to search any sequence of items ( the
collection implements the IEnumerable interface ) is to use a lambda
expression.
DateTime foundDate = dateList.FirstOrDefault(c => c >= searchDttm);

FindFirstOrDefault is the equivalent of Lookup.

The "c" in the lambda represents the item in the collection. If the
collection held rows from a database the lambda would read: c =>
c.OrderDate >= searchDttm.

The default value for an object is null. Since DateTime is a value
type, the default value is DateTime.MinValue ( how the method knows
that, I am not sure ;) )

here is some c# code that uses a lambda expression to find the first
date in a list that is >= the search date:

void DateLookup()
{
DateTime curDttm = DateTime.Now;
List<DateTime> dateList = new List<DateTime>();
for (int cx = 0; cx < 5; cx++)
{
dateList.Add(curDttm);
curDttm += new TimeSpan(7, 0, 0, 0); // 7 days
}

DateTime searchDttm = DateTime.Now + new TimeSpan(12, 0, 0, 0);
DateTime foundDate = dateList.FirstOrDefault(c => c >= searchDttm);

if (foundDate == DateTime.MinValue)
MessageBox.Show("date not found");
else
MessageBox.Show("found date " + foundDate.ToString());
}


-Steve

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].