× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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

As an Amazon Associate we earn from qualifying purchases.

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-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.