<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Visual Basic 2010</title>
	<atom:link href="http://vb2010.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vb2010.wordpress.com</link>
	<description>Making Visual Basic.NET even simpler</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:07:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='vb2010.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Visual Basic 2010</title>
		<link>http://vb2010.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://vb2010.wordpress.com/osd.xml" title="Visual Basic 2010" />
	<atom:link rel='hub' href='http://vb2010.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Multiply Collection Elements</title>
		<link>http://vb2010.wordpress.com/2011/09/07/multiply-collection-elements/</link>
		<comments>http://vb2010.wordpress.com/2011/09/07/multiply-collection-elements/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 06:31:53 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Aggregate]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Lambda Expression]]></category>
		<category><![CDATA[Multiply]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=202</guid>
		<description><![CDATA[Another post on the MSDN Forums, another idea for a blog. The title of the post was &#8220;Multiplying the Contents of an Array&#8221;. The OP wanted to know if there was a VB.NET equivalent to an Excel formula such as &#8220;=product(A1:A30)&#8221; , which would multiply all the elements in an array together. A few Forum [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=202&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Another post on the MSDN Forums, another idea for a blog. The title of the post was &#8220;Multiplying the Contents of an Array&#8221;. The OP wanted to know if there was a VB.NET equivalent to an Excel formula such as &#8220;=product(A1:A30)&#8221; , which would multiply all the elements in an array together.</p>
<p>A few Forum members responded with some usual and not so usual solutions: from a basic loop to an extension method. While .NET has some obvious built-in methods such as Sum and Average, these do not include one for the Product of all the elements of a collection. At least not an obvious one!</p>
<p><span id="more-202"></span></p>
<p>The Form for this is simple: just need 1 Button on the Form. And since the OP asked about an array, we&#8217;ll use that here, although you could use a List(Of T) also, which is what I would normally use.</p>
<p>To begin with, let&#8217;s instantiate a class-level array and populate it with a few values.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Dim myArray() As Double = New Double() {2.3, 4.8, 7.2}
&lt;/code&gt;
</pre></p>
<p>Double-click the Button on the Form to create the Button Click event in the code editor, and then put in this code.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ad As Double = MultiplyArray(myArray)
        Debug.WriteLine(ad)

    End Sub
&lt;/code&gt;
</pre></p>
<p>Pretty straightforward so far. We create a Double variable, and set it&#8217;s value to a method named MultiplyArray, passing our Double array to the function.</p>
<p>Now we&#8217;ll begin building our function. As can be seen, the name is MultiplyArray, with an array of Double as the argument, returning a Double.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Function MultiplyArray(ByVal somenumbers As Double()) As Double

    End Function
&lt;/code&gt;
</pre></p>
<p>So what do we need as the working code in the Function? Since we are returning a Double, we need a Double variable. We&#8217;ll also want to test if the array is Nothing and if the array has no elements, otherwise we&#8217;ll throw an exception. If it passes both those conditions, we can use a basic loop to multiply each element.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
        Dim prod As Double
        If Not somenumbers Is Nothing AndAlso Not somenumbers.Count = 0 Then
            prod = 1
            For Each d As Double In somenumbers
                prod *= d
            Next
        End If
        Return prod
&lt;/code&gt;
</pre></p>
<p>The double variable defaults to 0. If the If&#8230;Then fails on either the array being Nothing or the array not having any elements, then the functions returns 0. However, if the If&#8230;Then passes, we want to change our variable. If left at 0, remember multiplying by 0 equals 0, so we&#8217;ll give it a value of 1. Now we use a loop to iterate through all the items in the array and multiply each by the value of the variable. No matter what happens to the If&#8230;Then, the function returns the Double, whether it be 0 or some other number.</p>
<p>The member who posted the Extension Method made a comment about not being able to shorten the code. Just what I like &#8211; a challenge. My first thought was to look through the .NET methods, so I typed myArray, followed by a period so Intellisense would show me the available options. Hmmm&#8230;nothing jumped out. So, I went back through the list and looked at the tooltips that pop up explaining each one. Again, nothing obvious. But one that looked, well, different was Aggregate. Admittedly, I have never used this method before. But I learn a lot by trying different things. I decided to give that one a try.</p>
<p>The first thing I noticed was that it required &#8230; you guessed it, a Lambda Expression. Imagine that, after my previous few posts. Not sure what would work, I started with a Lambda with 2 arguments, and then multiplying the 2 arguments by each other in the &#8220;body&#8221; of the Lambda.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Function MultiplyArray(ByVal somenumbers As Double()) As Double
        Dim prod As Double
        If Not somenumbers Is Nothing AndAlso Not somenumbers.Length = 0 Then
            prod = somenumbers.Aggregate(Function(a, b) a * b)
        End If
        Return prod
    End Function
&lt;/code&gt;
</pre></p>
<p>It would be interesting to see what the function returned. Before I ran the app, I used a calculator to multiply the 3 numbers together. The answer was 79.488. Now let&#8217;s see what answer my app gives. I ran it, and printed in the Immedaite Window was (drum roll please):</p>
<p><span style="color:#ff0000;"><strong>79.488</strong></span></p>
<p>Wow! I was surprised, to put it mildly. And on my first try- that doesn&#8217;t happen very often.</p>
<p>I hope this gives you not only a nice way to multiply all the elements of a collection together, but also the idea to try different things in .NET. You never know what you&#8217;ll discover and learn.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=202&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/09/07/multiply-collection-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>DataTable to CSV</title>
		<link>http://vb2010.wordpress.com/2011/08/15/datatable-to-csv/</link>
		<comments>http://vb2010.wordpress.com/2011/08/15/datatable-to-csv/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 05:32:53 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[ItemArray]]></category>
		<category><![CDATA[Lambda Expression]]></category>
		<category><![CDATA[String.Join]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=195</guid>
		<description><![CDATA[There are many examples (and ways) available to save data from a DataTable to a csv TextFile. The vast majority utilize some type of loop to iterate through the rows and either  a string variable or a StringBuilder object to create the delimited line of text to save to the file. In this article I&#8217;m [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=195&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are many examples (and ways) available to save data from a DataTable to a csv TextFile. The vast majority utilize some type of loop to iterate through the rows and either  a string variable or a StringBuilder object to create the delimited line of text to save to the file.</p>
<p>In this article I&#8217;m going to show a slightly different approach.</p>
<p><span id="more-195"></span></p>
<p>To set up the Form, add a DataGridView and 2 Buttons from the ToolBox. Double click the Form&#8217;s TitleBar to create the Form Load event. First we&#8217;ll create a couple of class-level variables.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
    Dim dtTest As New DataTable
    Dim f_name As String = &quot;C:\Users\Joe\Desktop\Test Folder\createTxt.txt&quot;
    Dim sb As StringBuilder
&lt;/code&gt;
</pre></p>
<p>In the Form Load event we&#8217;ll add some Columns and then some records to the table. Then set the DataGridView DataSource property to the table.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 dtTest.Columns.Add(&quot;ID&quot;, GetType(Integer))
 dtTest.Columns.Add(&quot;Col2&quot;, GetType(String))
 dtTest.Columns.Add(&quot;Col3&quot;, GetType(Integer))

 Dim rndm As New Random
 For i As Integer = 65 To 70
 dtTest.Rows.Add(i, Chr(i), rndm.Next(100, 201))
 Next
 DataGridView1.DataSource = dtTest.DefaultView
 End Sub
&lt;/code&gt;
</pre></p>
<p>Now that we have some data in the table, in the first Button Click event we&#8217;ll run through a typical example of saving the data. Note that I have commented out the lines to write to the textfile and am merely writing to the Immediate Window within the IDE. I find this more useful when testing an app &#8211; I don&#8217;t have to keep opening the textfile to check the results. If it displays properly in the Immediate Window, it will write properly to the textfile.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

         Using sw As New StreamWriter(f_name, False)
            sb = New StringBuilder
            For Each dcol As DataColumn In dtTest.Columns
                sb.Append(dcol.ColumnName &amp; &quot;,&quot;)
            Next

            'sw.WriteLine(sb.ToString)
            Debug.WriteLine(sb.ToString)
            For Each drow As DataRow In dtTest.Rows
                sb = New StringBuilder
                For i As Integer = 0 To dtTest.Columns.Count - 1
                    sb.Append(drow.Item(i).ToString &amp; &quot;,&quot;)
                Next

                'sw.WriteLine(sb.ToString)
                Debug.WriteLine(sb.ToString)
            Next
        End Using
    End Sub
&lt;/code&gt;
</pre></p>
<p>There are 3 loops here. The first loops through the Columns in the table and creates the first line with the column names. After that the second loops through all the Rows in the table. The third is a nested loop to iterate through all the Items (Columns) within that row and create a comma delimited line for the data in each row. If you run the app you should get 7 lines in the Immediate Window. Try it now.</p>
<p>Did you notice anything? Hopefully you noticed each line has an extra comma at the end because of the way we have used the StringBuilder to create each line. This can be corrected by adding this to the code right above both commented out sw.WriteLine lines. In the code above I have thoughtfully left a blank line for you to add it in <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><pre class="brush: vb;">
&lt;code&gt;
sb.Remove(sb.Length - 1, 1)
&lt;/code&gt;
</pre></p>
<p>While that code isn&#8217;t too complicated or messy, now we&#8217;ll look at another option using String.Join, a Lambda Expression and the Column and DataRow collections from the table. It will also use the ItemArray property of each DataRow to simplify retrieving each field from a row. The only loop required will be one to iterate through the DataRow collection.</p>
<p>Let&#8217;s tackle the Columns first. In the Click event of the second button, add this code.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnSave2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave2.Click
        Using sw As New StreamWriter(f_name, False)
            Dim cols As String = String.Join(&quot;,&quot;, dtTest.Columns.Cast(Of DataColumn)().Select(Function(c) c.ColumnName).ToArray())
            'sw.WriteLine(cols)
            Debug.WriteLine(cols)

        End Using
    End Sub
&lt;/code&gt;
</pre></p>
<p>If you run this now, you should get a line with the Column names separated by a comma. The advantage of using String.Join is you don&#8217;t end up with the extra comma at the end of the line. And it&#8217;s a nice compact one line of code to get all the Column names using the Select method along with a Lambda Expression. Pretty neat, huh?</p>
<p>But now we need the data from the table, also. We will need to iterate through the DataRow collection with a loop, but by using String.Join and a Lambda Expression with the DataRow ItemArray property, we can avoid the nested loop to get each Item from each row to create our comma-separated line. Add this block right above the End Using line.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
For Each drow As DataRow In dtTest.Rows
                Dim lineoftext = String.Join(&quot;,&quot;, drow.ItemArray.Select(Function(s) s.ToString).ToArray)
                'sw.WriteLine(lineoftext)
                Debug.WriteLine(lineoftext)
            Next
&lt;/code&gt;
</pre></p>
<p>When you run the completed code, the output from both Buttons should be the same. However, I find the second option much cleaner code-wise. You don&#8217;t have the nested loops and you don&#8217;t have to remove a comma from the end of the string.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=195&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/08/15/datatable-to-csv/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions &#8211; I thought I was done</title>
		<link>http://vb2010.wordpress.com/2011/08/02/lambda-expressions-i-thought-i-was-done/</link>
		<comments>http://vb2010.wordpress.com/2011/08/02/lambda-expressions-i-thought-i-was-done/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 06:33:36 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[FileInfo]]></category>
		<category><![CDATA[Lambda Expression]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=184</guid>
		<description><![CDATA[Since the time I &#8220;finished&#8221; this series of articles on Lambda Expressions, there were a couple of more questions asked on the Forums that lent themselves well to using a Lambda Expression. I thought I would discuss those here to provide some more ideas on the use of LEs. I&#8217;ve also included a solution using a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=184&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since the time I &#8220;finished&#8221; this series of articles on Lambda Expressions, there were a couple of more questions asked on the Forums that lent themselves well to using a Lambda Expression. I thought I would discuss those here to provide some more ideas on the use of LEs. I&#8217;ve also included a solution using a LINQ query, since they go hand-in-hand.</p>
<p><span id="more-184"></span></p>
<p>The first post was &#8220;getting the most recently modified file in a folder with wildcards (e.g. file *.txt)&#8221;.</p>
<p>Like many things in .NET, there are usually many ways to get what you want. In this case, first you have to decide what to use to retrieve all the files from a folder with a particular extension. The DirectoryInfo Class has a nice overloaded method named GetFiles. This allows you to specify a search pattern, as well as search option specifying to search the top-directory only or all directories. This is different than the System.IO Directory Class, which also has a GetFiles method, allowing you to also specify a search pattern and search option. The difference is the Directory GetFiles method returns an array of the File names. The DirectoryInfo Class GetFiles method returns an array of FileInfo objects.</p>
<p>Before we go any further let&#8217;s set up our Form. Add 2 Buttons and 3 ListBoxes. Since the GetFiles method returns an array, we&#8217;ll need a collection to hold them. Except in rare cases I use a List(Of T). In the Button1 Click event declare a List(Of FileInfo), and also declare a DirectoryInfo object, using the path to a folder containg a number of different file types. Then fill the List using the GetFiles method, using .txt as the search pattern and TopDirectoryOnly for the search option. Once the List is populated, we&#8217;ll iterate through it and add the file name and last write time to ListBox1.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Dim lstFiles As New List(Of FileInfo)
        Dim dInfo As New DirectoryInfo(&quot;C:\Users\Joe\Desktop\Test Folder&quot;)

        lstFiles = dInfo.GetFiles(&quot;*.txt&quot;, SearchOption.TopDirectoryOnly).ToList

        For Each fi As FileInfo In lstFiles
            ListBox1.Items.Add(fi.Name &amp; &quot;   &quot; &amp; fi.LastWriteTime.ToShortDateString)
        Next
&lt;/code&gt;
</pre></p>
<p>Since I have the files in the folder sorted by name, the items should be added in alphabetical order by file name. Next we&#8217;ll use the Sort method of the List(Of T), performing the sort with a Lambda Expression. Now that the List is sorted, we can iterate through it again, adding the file name and last write time to ListBox2. Now the files should be listed in ascending order by last write time. Add this to the Button1 Click event:</p>
<p><pre class="brush: vb;">
&lt;code&gt;
lstFiles.Sort(Function(a, b) Date.Compare(a.LastWriteTime, b.LastWriteTime))

        Debug.WriteLine(String.Format(&quot;{0} was last modified on {1}&quot;, lstFiles(0).Name, lstFiles(0).LastWriteTime)) 'oldest file
        Debug.WriteLine(String.Format(&quot;{0} was last modified on {1}&quot;, lstFiles(lstFiles.Count - 1).Name, lstFiles(lstFiles.Count - 1).LastWriteTime)) 'newest file

        For Each fi As FileInfo In lstFiles
            ListBox2.Items.Add(fi.Name &amp; &quot;   &quot; &amp; fi.LastWriteTime.ToShortDateString)
        Next
&lt;/code&gt;
</pre></p>
<p>Note that if you want to sort in descending order, you can reverse the  FileInfo parameters within the Lambda Expression:</p>
<p><pre class="brush: vb;">
&lt;code&gt;
lstFiles.Sort(Function(a, b) Date.Compare(b.LastWriteTime, a.LastWriteTime))
&lt;/code&gt;
</pre></p>
<p>In the Button2 Click event, we&#8217;ll use a LINQ query with an Order By clause, specifying Descending. Then iterate through the List again, adding the items to ListBox3.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim lstFiles As New List(Of FileInfo)
        Dim dInfo As New DirectoryInfo(&quot;C:\Users\Joe\Desktop\Test Folder&quot;)

        lstFiles = dInfo.GetFiles(&quot;*.txt&quot;).ToList
        Dim query = From fn In lstFiles.AsEnumerable Order By fn.LastWriteTime Descending

        Debug.WriteLine(String.Format(&quot;{0} was last modified on {1}&quot;, query(0).Name, query(0).LastWriteTime)) 'newest file
        Debug.WriteLine(String.Format(&quot;{0} was last modified on {1}&quot;, query(query.Count - 1).Name, query(query.Count - 1).LastWriteTime)) 'oldest file

        For Each fi As FileInfo In query
            ListBox3.Items.Add(fi.Name &amp; &quot;   &quot; &amp; fi.LastWriteTime.ToShortDateString)
        Next
    End Sub
&lt;/code&gt;
</pre></p>
<p>The second Forum post was a question about getting a count of each item in an Excel column. The OP has an Excel sheet containing a list of students and their ages, and wants to get the count of students at each age: x number of 5 year olds, y number of 6 year olds, etc. Sounded like a fun question to work on!</p>
<p>Unfortunately this was a question about VBA, and I don&#8217;t know if VBA supports Lambda Expressions (or even LINQ). However, I still decided to solve the question using .NET. Create an app with 2 Buttons, 2 ListBoxes and a DataGridView on the Form. We&#8217;ll instantiate a DataTable to hold the data (simulating the Excel sheet) and display it in the DataGridView.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Dim dtTest As New DataTable

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dtTest.Columns.Add(&quot;F_Name&quot;, GetType(String))
        dtTest.Columns.Add(&quot;G_Class&quot;, GetType(String))
        dtTest.Columns.Add(&quot;Age&quot;, GetType(Integer))

        Dim rndm As New Random
        For i As Integer = 1 To 10
            dtTest.Rows.Add(Chr(rndm.Next(65, 91)), Chr(rndm.Next(97, 102)), rndm.Next(5, 16))
        Next
        DataGridView1.DataSource = dtTest.DefaultView
    End Sub
&lt;/code&gt;
</pre></p>
<p>We&#8217;ll start with the LINQ query in the Button1 Click event.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 5 To 15
            Dim int As Integer = i
            Dim cnt As Integer = (From n In dtTest.AsEnumerable Where n.Field(Of Integer)(&quot;Age&quot;) = int Select n).Count
            If Not cnt = 0 Then
                ListBox1.Items.Add((String.Format(&quot;There are {0} children aged {1} years&quot;, cnt.ToString, int.ToString)))
            End If
        Next
    End Sub
&lt;/code&gt;
</pre></p>
<p>And the corresponding LE:</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For i As Integer = 5 To 15
            Dim int As Integer = i
            Dim cnt = dtTest.AsEnumerable.Count(Function(a) a.Field(Of Integer)(&quot;Age&quot;) = int)
            If Not cnt = 0 Then
                ListBox2.Items.Add((String.Format(&quot;There are {0} children aged {1} years&quot;, cnt.ToString, int.ToString)))
            End If
        Next
    End Sub
&lt;/code&gt;
</pre></p>
<p>A couple of more examples of the ability of LINQ and LEs to perform different tasks in .NET.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=184&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/08/02/lambda-expressions-i-thought-i-was-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions &#8211; Final(ly)</title>
		<link>http://vb2010.wordpress.com/2011/07/29/lambda-expressions-finally/</link>
		<comments>http://vb2010.wordpress.com/2011/07/29/lambda-expressions-finally/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 05:42:08 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[inline functions]]></category>
		<category><![CDATA[Lambda Expression]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=180</guid>
		<description><![CDATA[This is the final part on the series about Lambda Expressions. I thought I would end it with an explanation of the motivation to write a little about LEs.  As with many of the articles I&#8217;ve written, the inspiration comes from what I think is an interesting solution to a problem posted on the Forums. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=180&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the final part on the series about Lambda Expressions. I thought I would end it with an explanation of the motivation to write a little about LEs.  As with many of the articles I&#8217;ve written, the inspiration comes from what I think is an interesting solution to a problem posted on the Forums.</p>
<p>If you&#8217;d like a short description of the posted question and an extremely ingenious use of Lambda Expressions to solve it&#8230;<span id="more-180"></span></p>
<p>To begin with, I need to say right off the bat that the LE used to solve the coding question was supplied by another Forum user (with a slight modification by me). I cannot take credit for it, but it is one of those rare pieces of code I come across that makes me step back and say &#8220;Wow, that is really cool&#8221;. I would never have thought of a LE used in the way it was to solve the problem. But it also prompted me to take a closer look at LEs and what can be done with them. And like so much in .NET, the more I looked, the more I learned.</p>
<p>So, for background here is a brief synopsis of the posted question. The OP had an app with a ComboBox. The ComboBox was populated with data (from where I can&#8217;t remember), but was in the form of C1, C2, C3&#8230; up to I think C1000. The problem was they were not populated in that order, from 1 to 1000. They were not in any pattern &#8211; essentially they were random. He was attempting to sort the items, and that was were the problem lied. If they were strictly of a numeric datatype, the solution would be simple. Since they were strings, setting the ComboBox Sorted property to True would not work, as strings are sorted position by position.</p>
<p>Any of you that have had this form of data in a ComboBox and have tried to sort it know that you will get C1, C10, C100&#8230;C2, C20, etc. C10, C11&#8230; will come before C2; since the first character is the same, it then compares the next. And 1 comes before 2, so all of the C1xx items will come before C2xx.</p>
<p>Obviously to get it to sort properly, you would need to strip off the first character so all you are left with is a number. I was getting ready to post some quite involved string manipulations and loops to perform this. I rechecked the post to make sure I had understood everything correctly (I&#8217;ve learned from my mistakes in the past &#8211; not understanding something and posted code that is missing one critical piece, or does the wrong thing). Lo and behold, another Forum member had posted a solution that completely took the air out of my balloon. It was so simple and elegant, all I could do was tell the poster it was a nice piece of work and propose it as the answer. So what was it that humbled and awed me so much? Well, before we get to that, we need to set up our app so you can see it work.</p>
<p>First, create an app with a ListBox and a 3 Buttons. I am using a ListBox so you can see a large number of the items as you run through the code, to more easily visualize what is happening. In the Form Load event we&#8217;ll load the ListBox with our items.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For i As Integer = 1 To 250
            ListBox1.Items.Add(&quot;A&quot; &amp; i.ToString)
        Next

    End Sub
&lt;/code&gt;
</pre></p>
<p>You can readily see that the items will already be sorted correctly because they are added in order. Remember the items, however, were being added randomly. To mimic this, in the Button1 Click event we&#8217;ll set the ListBox Sorted property to True.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Sorted = True
    End Sub
&lt;/code&gt;
</pre></p>
<p>Now, in order to get our method to sort the items how we want, we need to set the Sorted property back to False, which is done in the Button2 Click event.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Sorted = False
    End Sub
&lt;/code&gt;
</pre></p>
<p>Last but not least, in the Button3 Click event we&#8217;ll have our LE to sort the items properly. Note that the first two commented blocks of code are the solutions posted. The third is my slight modification &#8211; and very slight it is.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Dim items() As String = ListBox1.Items.Cast(Of String).ToArray
        'Array.Sort(items, Function(x, y) CInt(x.Substring(1)).CompareTo(CInt(y.Substring(1))))
        'ListBox1.Items.Clear()
        'ListBox1.Items.AddRange(items)

        'Dim items() As String = ListBox1.Items.Cast(Of String).OrderBy(Function(s) CInt(s.Substring(1))).ToArray
        'ListBox1.Items.Clear()
        'ListBox1.Items.AddRange(items)

        Dim query = ListBox1.Items.Cast(Of String).OrderBy(Function(s) CInt(s.Substring(1))).ToArray
        ListBox1.Items.Clear()
        ListBox1.Items.AddRange(query)
    End Sub
&lt;/code&gt;
</pre></p>
<p>OK&#8230;now that we have all the code done, it&#8217;s time to run it. Hit F5 to start debugging. All the items in the ListBox will be ordered, since they were added that way. But we need to unorder them. Click Button1, which sets the Sorted property to True. Now the items will be sorted as strings; in which case they are sorted improperly.</p>
<p>Before we can run the LE, we need to reset the Sorted property to False. Otherwise, even though we have code to sort it how we want, with this property set to True, when the items are added back into the ListBox the same problem will recur. Click Button2 to change the Sorted property. This will not change the items in the ListBox &#8211; we are merely making it so the default sorting method of the ListBox does not override our code.</p>
<p>To see the LE in action, click Button3.</p>
<p>No more needs to be said.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=180&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/07/29/lambda-expressions-finally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions &#8211; Part 3</title>
		<link>http://vb2010.wordpress.com/2011/07/28/lambda-expressions-part-3/</link>
		<comments>http://vb2010.wordpress.com/2011/07/28/lambda-expressions-part-3/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 07:04:35 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[inline functions]]></category>
		<category><![CDATA[Lambda Expressions]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=176</guid>
		<description><![CDATA[In the first two parts of this series, some examples of LEs were shown. In this part we will review some more examples. Note that these are coded in VS2010. The reason being one of the examples uses a Sub instead of a Function, and the Sub type LE is not available in VS2008. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=176&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the first two parts of this series, some examples of LEs were shown. In this part we will review some more examples. Note that these are coded in VS2010. The reason being one of the examples uses a Sub instead of a Function, and the Sub type LE is not available in VS2008. I have also included some of the info from MSDN on LEs, specifically the discussion about the LE syntax and how it differs from a standard function or subroutine.</p>
<p>So without further delay, let&#8217;s get on with it.<span id="more-176"></span></p>
<p>Before we get to the code, here is the info from MSDN on LEs:</p>
<blockquote><p><span style="color:#0000ff;">The syntax of a lambda expression resembles that of a standard function or subroutine. The differences are as follows:</span></p></blockquote>
<ul>
<li><span style="color:#0000ff;">A lambda expression does not have a name.</span></li>
<li><span style="color:#0000ff;">Lambda expressions cannot have modifiers, such as Overloads or Overrides.</span></li>
<li><span style="color:#0000ff;">Single-line lambda functions do not use an As clause to designate the return type. Instead, the type is inferred from the value that the body of the lambda expression evaluates to. For example, if the body of the lambda expression is cust.City = &#8220;London&#8221;, its return type is Boolean.</span></li>
<li><span style="color:#0000ff;">In multi-line lambda functions, you can either specify a return type by using an As clause, or omit the As clause so that the return type is inferred. When the As clause is omitted for a multi-line lambda function, the return type is inferred to be the dominant type from all the Return statements in the multi-line lambda function. The dominant type is a unique type that all other types supplied to the Return statement can widen to. If this unique type cannot be determined, the dominant type is the unique type that all other types supplied to the Return statement can narrow to. If neither of these unique types can be determined, the dominant type is Object.</span><span style="color:#0000ff;">For example, if the expressions supplied to the Return statement contain values of type Integer, Long, and Double, the resulting type is Double. Both Integer and Long widen to Double and only Double. Therefore, Double is the dominant type. For more information, see <a href="http://msdn.microsoft.com/en-us/library/k1e94s7e.aspx"><span style="color:#0000ff;">Widening and Narrowing Conversions (Visual Basic)</span></a>.</span></li>
<li><span style="color:#0000ff;">The body of a single-line function must be an expression that returns a value, not a statement. There is no Return statement for single-line functions. The value returned by the single-line function is the value of the expression in the body of the function.</span></li>
<li><span style="color:#0000ff;">The body of a single-line subroutine must be single-line statement.</span></li>
<li><span style="color:#0000ff;">Single-line functions and subroutines do not include an End Function or End Sub statement.</span></li>
<li><span style="color:#0000ff;">You can specify the data type of a lambda expression parameter by using the As keyword, or the data type of the parameter can be inferred. Either all parameters must have specified data types or all must be inferred.</span></li>
<li><span style="color:#0000ff;">Optional and Paramarray parameters are not permitted.</span></li>
<li><span style="color:#0000ff;">Generic parameters are not permitted.</span></li>
</ul>
<p><span style="color:#000000;">For these examples you&#8217;ll need a WinForm app with five Buttons and two TextBoxes. In the Form Load event we&#8217;ll populate the TextBoxes with numbers &#8211; you can change these before clicking the appropriate Button to see the output change.</span></p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = &quot;4&quot;
        TextBox2.Text = &quot;7&quot;
    End Sub
&lt;/code&gt;
[/sourccode]

In the Button1 Click event below, we will show a Sub type LE - up to this point in the previous parts all have been a Function.

[sourcecode language=&quot;vb&quot;]
&lt;code&gt;
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ShowAMessage = Sub(x) MessageBox.Show(x)
        ShowAMessage(&quot;Hello world&quot;)

        MessageBox.Show((Function(i As Integer) i + 5)(5))
    End Sub
&lt;/code&gt;
</pre></p>
<p>In this example the LE is assigned to a variable name. Whenever you refer to the variable, you invoke the LE. And that is another difference between a LE and a standard Function: with a standard Function, the Function is created when the app compiles &#8211; utilizing unnecessary resources; the LE is only created when called. Note that the datatype of x is not defined. If you hover your mouse over x in the code editor, you&#8217;ll see it&#8217;s type as Object. And the ShowAMessage type is defined as &lt;Sub(Object)&gt;, which is the LE. And since LEs are typed as delegates, they can be called, but also can be passed as a parameter to another method.</p>
<p>The second LE above shows another handy feature: you can declare and invoke a LE all at the same time.</p>
<p>Another  point to note in the Button2 Click event below is the parameter list for the Delegate Function. The last parameter is the return type, and the others are the argument parameters. In VS2008 the argument parameters were limited to four; in VS2010 the number is increased.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer = 20
        Dim doubleIt As Func(Of Integer, Integer) = Function(x) x * 2
        Dim z = doubleIt(i)
        MessageBox.Show(i.ToString &amp; &quot; doubled equals &quot; &amp; z.ToString)

    End Sub
&lt;/code&gt;
</pre></p>
<p>If you hover your mouse over the variable z above, you&#8217;ll see it is of type Integer, even though it was not declared as such. The reason being the datatype was inferred from the return type specified in the delegate function.</p>
<p>The following Button Click events show how a LE can be passed to another method as an argument.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        testIfTrue(CInt(TextBox1.Text), Function(num) num Mod 2 = 0)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        testIfTrue(CInt(TextBox2.Text), Function(num) num &gt; 10)
    End Sub

    Sub testIfTrue(ByVal int As Integer, ByVal MyTest As Func(Of Integer, Boolean))
        If MyTest(int) Then
            MessageBox.Show(&quot;True&quot;)
        Else
            MessageBox.Show(&quot;False&quot;)
        End If
    End Sub
&lt;/code&gt;
</pre></p>
<p>Finally, in the Button5 Click event we pass two integers and a LE to another method, with the integers being used as the argument parameters for the LE.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        testProduct(CInt(TextBox1.Text), CInt(TextBox2.Text), Function(x, y) x * y &gt; 50)
    End Sub

    Sub testProduct(ByVal int1 As Integer, ByVal int2 As Integer, ByVal MyTest2 As Func(Of Integer, Integer, Boolean))
        If MyTest2(int1, int2) Then
            MessageBox.Show(int1.ToString &amp; &quot; times &quot; &amp; int2.ToString &amp; &quot; is greater than 50&quot;)
        Else
            MessageBox.Show(int1.ToString &amp; &quot; times &quot; &amp; int2.ToString &amp; &quot; is less than 50&quot;)
        End If
    End Sub
&lt;/code&gt;
</pre></p>
<p>I hope this has given you some more insight into using LEs. As mentioned earlier, they can be a great addition to your code due to their power, flexibility and conciseness. Again, I encourage you to play around with them in your code and find some interesting ways they can be used.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/176/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/176/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/176/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=176&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/07/28/lambda-expressions-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions &#8211; Part 2</title>
		<link>http://vb2010.wordpress.com/2011/07/27/lambda-expressions-part-2/</link>
		<comments>http://vb2010.wordpress.com/2011/07/27/lambda-expressions-part-2/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 07:32:33 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Distinct]]></category>
		<category><![CDATA[Lambda Expressions]]></category>
		<category><![CDATA[OrderBy]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=173</guid>
		<description><![CDATA[In the first part of this series  we used some simple LEs to query a List(Of String). As you saw in the examples LEs can be a powerful tool to not only extract the data, but also shorten your code. Part 2 will expand on what was learned by applying the same principles to a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=173&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the first part of this series  we used some simple LEs to query a List(Of String). As you saw in the examples LEs can be a powerful tool to not only extract the data, but also shorten your code.</p>
<p>Part 2 will expand on what was learned by applying the same principles to a List(Of T) containing custom objects. Note that the code for this article was written in VS2010. The only reason being I&#8217;m lazy and wanted to utilize the auto-implemented properties new to Visual Basic in 2010. If you will be working in VS2008, you&#8217;ll need to add the Get and Set code blocks for the properties.</p>
<p><span id="more-173"></span></p>
<p>As always the first step will be to creat the Form with the controls. For this part you&#8217;ll need to add three Buttons, two TextBoxes, one ComboBox and one ListBox. Next we need to create our custom Class, so after the End Class line for Form1, insert the following code.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Public Class Employee
    Public Property Name As String
    Public Property Dept As String
    Public Property Salary As Integer
    Public Property DOH As Date
End Class
&lt;/code&gt;
</pre></p>
<p>Then we&#8217;ll need a global List(Of Employee) and in the Form1 Load event, add some Employee objects to the List.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Dim lstEmployees As New List(Of Employee)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lstEmployees.Add(New Employee With {.Name = &quot;Kris&quot;, _
                                .Dept = &quot;IT&quot;, _
                                .Salary = 60000, _
                                .DOH = #12/25/2001#})
        lstEmployees.Add(New Employee With {.Name = &quot;Jack&quot;, _
                                .Dept = &quot;Billing&quot;, _
                                .Salary = 30500, _
                                .DOH = #10/31/2006#})
        lstEmployees.Add(New Employee With {.Name = &quot;Kevin&quot;, _
                                .Dept = &quot;Admin&quot;, _
                                .Salary = 98000, _
                                .DOH = #4/1/2010#})
        lstEmployees.Add(New Employee With {.Name = &quot;Sam&quot;, _
                                        .Dept = &quot;HR&quot;, _
                                        .Salary = 45500, _
                                        .DOH = #7/4/1976#})
        lstEmployees.Add(New Employee With {.Name = &quot;Ebenezer&quot;, _
                                .Dept = &quot;Billing&quot;, _
                                .Salary = 57200, _
                                .DOH = #4/15/1980#})
        lstEmployees.Add(New Employee With {.Name = &quot;Rachel&quot;, _
                                .Dept = &quot;HR&quot;, _
                                .Salary = 52000, _
                                .DOH = #2/14/2004#})
        lstEmployees.Add(New Employee With {.Name = &quot;Katie&quot;, _
                                .Dept = &quot;IT&quot;, _
                                .Salary = 42750, _
                                .DOH = #1/1/1998#})

        'load distinct Dept into ComboBox
        'Dim query = (lstEmployees.Select(Function(d) d.Dept).Distinct).ToArray
        'ComboBox1.DataSource = query

        'load distinct Dept into ComboBox alphabetically
        Dim query2 = lstEmployees.Select(Function(d) d.Dept).OrderBy(Function(d) d).Distinct.ToArray
        ComboBox1.DataSource = query2

    End Sub
&lt;/code&gt;
</pre></p>
<p>The first thing to notice here is the code blocks to add all the distinct Employee Dept properties into the ComboBox. These utilize a LE to find the Distinct items, with the second one including an OrderBy to list them alphabetically.</p>
<p>To start we&#8217;ll use the List FindAll method, and filter our Employee List by DOH (Date of Hire) and Salary. The first example has a hard-coded DOH and Salary. The second has a hard-coded DOH, but will require you to enter a Salary level in TextBox1. Be forewarned &#8211; there is no validation included that what you enter is actually a number. If you enter 40000 in TextBox1, the first two sections in the ListBox will be th same. There is a slight difference in the LE, but the results will be the same. The third has a hard-coded DOH and Salary also (the same as the first), along with an OrderBy to sort the results by the Name property.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim query = lstEmployees.FindAll(Function(d) d.DOH &lt; #1/1/2000# And d.Salary &gt; 40000)
        For Each item As Employee In query
            ListBox1.Items.Add(item.Name &amp; &quot;  &quot; &amp; item.DOH.ToShortDateString &amp; &quot;  &quot; &amp; item.Salary)
        Next

        ListBox1.Items.Add(&quot;  &quot;)

        Dim query2 = lstEmployees.FindAll(Function(emp) emp.DOH &lt; #1/1/2000#).Where(Function(emp) emp.Salary &gt; CInt(TextBox1.Text))
        For Each item As Employee In query2
            ListBox1.Items.Add(item.Name &amp; &quot;  &quot; &amp; item.DOH.ToShortDateString &amp; &quot;  &quot; &amp; item.Salary)
        Next

        ListBox1.Items.Add(&quot;  &quot;)

        Dim query3 = lstEmployees.FindAll(Function(f) f.DOH &lt; #1/1/2000# And f.Salary &gt; 40000).OrderBy(Function(emp) emp.Name)
        For Each item As Employee In query3
            ListBox1.Items.Add(item.Name &amp; &quot;  &quot; &amp; item.DOH.ToShortDateString &amp; &quot;  &quot; &amp; item.Salary)
        Next

    End Sub
&lt;/code&gt;
</pre></p>
<p>Next, we&#8217;ll search for all employees whose Name starts with a certain letter &#8211; to be typed into TextBox2 - and then sort them by Salary.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim query = lstEmployees.FindAll(Function(emp) emp.Name.StartsWith(TextBox2.Text.ToUpper)).OrderBy(Function(emp) emp.Salary)
        For Each item As Employee In query
            ListBox1.Items.Add(item.Name &amp; &quot;  &quot; &amp; item.Salary)
        Next
    End Sub
&lt;/code&gt;
</pre></p>
<p>Finally, we&#8217;ll select a Dept from the ComboBox and then search for all Employees from that Dept, displaying the Name and Salary in the ListBox.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim query = lstEmployees.FindAll(Function(c) c.Dept = ComboBox1.SelectedItem.ToString)
        ListBox1.Items.Add(&quot;Employees from &quot; &amp; ComboBox1.SelectedItem.ToString)
        For Each item As Employee In query
            ListBox1.Items.Add(item.Name &amp; &quot;  &quot; &amp; item.Salary)
        Next
    End Sub
&lt;/code&gt;
</pre></p>
<p>Hopefully this has given you an idea of the power and flexibility of LEs. I would suggest to explore them further by writing some more LEs, trying different ways to filter the data in the List. Have fun!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=173&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/07/27/lambda-expressions-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expressions: An Intro</title>
		<link>http://vb2010.wordpress.com/2011/07/26/lambda-expressions-an-intro/</link>
		<comments>http://vb2010.wordpress.com/2011/07/26/lambda-expressions-an-intro/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 07:12:33 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[inline functions]]></category>
		<category><![CDATA[Lambda Expression]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=169</guid>
		<description><![CDATA[Lambda Expressions (also known as Inline Functions) can be a powerful tool to use. So what exactly are Lambda Expressions? I found many different definitions and descriptions, so rather than try to provide one here, I&#8217;ll leave it up to you to do a little research and come up with your own idea. Also to get an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=169&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lambda Expressions (also known as Inline Functions) can be a powerful tool to use. So what exactly are Lambda Expressions? I found many different definitions and descriptions, so rather than try to provide one here, I&#8217;ll leave it up to you to do a little research and come up with your own idea. Also to get an idea of the power and flexibility they offer.</p>
<p>The purpose of this first article (there will be more &#8211; how many is unknown at this time) is to show some simple examples utilizing a List(Of T). Lambda Expressions are essential in many of the native List methods, such as Find, FindAll, etc.<span id="more-169"></span></p>
<p>In order to use Lambda Expressions (from this point on they will be referred to as LEs &#8211; I hate typing it out over and over) on a List(Of T), we first must have a List to work with. And of course an app with some controls. So the first step is to create a WinForm app with two ListBoxes and three Buttons. Then define a List(Of String) globally as we will be using it in the Button Click event for all three Buttons. In the Form Load event we will add a few items to the List.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Dim lstAnimals As New List(Of String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lstAnimals.AddRange(New String() {&quot;cow&quot;, &quot;horse&quot;, &quot;pig&quot;, &quot;duck&quot;, &quot;goat&quot;, &quot;dog&quot;})
        ListBox1.DataSource = lstAnimals

    End Sub
&lt;/code&gt;
</pre></p>
<p>In the Click event for Button1, we&#8217;ll go through some very basic examples. In each example, a standard For Each loop is performed on the List, followed by it&#8217;s LE equivalent. The main advantage here is that the LEs require much less code.</p>
<p>The first set of Loop/LE will find the first word with 4 characters and the next will find the last word with 4 characters. The final set of Loop/LE will get the Index within the List of the first word that starts with the letter d.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Debug.WriteLine(&quot;first four-letter word:&quot;)
        'find first of length = 4
        For Each a As String In lstAnimals
            If a.Length = 4 Then
                Debug.WriteLine(&quot;Loop: &quot; &amp; a)
                Exit For
            End If
        Next

        Debug.WriteLine(&quot;Lambda: &quot; &amp; lstAnimals.Find(Function(a) a.Length = 4))

        Debug.WriteLine(&quot;last four-letter word:&quot;)
        'find last of length = 4
        For i As Integer = lstAnimals.Count - 1 To 0 Step -1
            If lstAnimals(i).Length = 4 Then
                Debug.WriteLine(&quot;Loop: &quot; &amp; lstAnimals(i))
                Exit For
            End If
        Next

        Debug.WriteLine(&quot;Lambda: &quot; &amp; lstAnimals.FindLast(Function(a) a.Length = 4))

        Debug.WriteLine(&quot;index of first that starts with d:&quot;)
        'get index of first that starts with d
        For Each a As String In lstAnimals
            If a.StartsWith(&quot;d&quot;) Then
                Debug.WriteLine(&quot;Loop: &quot; &amp; lstAnimals.IndexOf(a))
                Exit For
            End If
        Next

        Debug.WriteLine(&quot;Lambda: &quot; &amp; lstAnimals.FindIndex(Function(a) a.StartsWith(&quot;d&quot;)))

    End Sub
&lt;/code&gt;
</pre></p>
<p>Pretty simple. In the Click event of Button2, we&#8217;ll go through an example of searching the List again, this time finding all words of Length = 3, and displaying them in ListBox2.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'find all of length = 3
        ListBox2.Items.Add(&quot;Loop:&quot;)

        For Each s As String In lstAnimals
            If s.Length = 3 Then
                ListBox2.Items.Add(s)
            End If
        Next

        ListBox2.Items.Add(&quot; &quot;)
        ListBox2.Items.Add(&quot;Lambda:&quot;)

        ListBox2.Items.AddRange(lstAnimals.FindAll(Function(a) a.Length = 3).ToArray)
    End Sub
&lt;/code&gt;
</pre></p>
<p>Again, pretty simple. Finally, in Button3&#8242;s Click event we will get the character count for all the words in the List.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'get number of characters of all items
        Dim totalLoop As Integer
        For Each s As String In lstAnimals
            totalLoop += s.Length
        Next
        Debug.WriteLine(&quot;Loop total length = &quot; &amp; totalLoop)

        Dim totalLambda = lstAnimals.Sum(Function(a) a.Length)
        Debug.WriteLine(&quot;Lambda total length = &quot; &amp; totalLambda)
    End Sub
&lt;/code&gt;
</pre></p>
<p>One item to note is the lack of parameter type in the LE. The compiler will infer the type &#8211; otherwise known as implicit typing. There are times when the parameter type must be explicitly defined, but when unnecessary can save you some time and cause less clutter in your code.</p>
<p>In the next part we will get into some slightly more difficult examples. And instead of a simple List(Of String), we will use a  Class with properties in the List.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=169&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/07/26/lambda-expressions-an-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Letter Scramble</title>
		<link>http://vb2010.wordpress.com/2011/07/19/letter-scramble/</link>
		<comments>http://vb2010.wordpress.com/2011/07/19/letter-scramble/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 05:23:06 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Letter scramble]]></category>
		<category><![CDATA[Random characters]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=162</guid>
		<description><![CDATA[A post on the Forums asked how to select a random word from an array, then reverse the letters.  Pretty simple using the Reverse  method. I decided to take it one step further and rearrange the letters randomly. After completing the task, I searched the Internet for other examples. In my opinion, the solution below [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=162&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A post on the Forums asked how to select a random word from an array, then reverse the letters.  Pretty simple using the Reverse  method.</p>
<p>I decided to take it one step further and rearrange the letters randomly. After completing the task, I searched the Internet for other examples. In my opinion, the solution below is more efficient than others I found.<span id="more-162"></span></p>
<p>Most of the samples found used a couple of loops, had to test for the position in the character array with each pass, swap one letter for another, etc, which I found tedious and excessively long.</p>
<p>I looked at it the same way I would if I were to select, say, 6 random numbers from a List with no repeats, such as for some type of game. One way that I frequently see is to use two Lists &#8211; one for the original complete List, and one to store the selected numbers. When a new number is selected, an If&#8230;Then block is used to check if that number is in the second List (using Contains). I find this inefficient also, as you may be selecting numbers numerous times, thus performing the Loop unnecessarily until you get the correct number of items in the second List.</p>
<p>To begin with, let&#8217;s set up our Form. For all the controls, the names can be found in the events shown. You&#8217;ll need two Buttons (one to select a random word and one to submit your guess), one Label (to display the scrambled word) and one TextBox (to input your guess).</p>
<p>Next, we&#8217;ll set up our Class level variables (those needed in more than one method) and add a few words to a List(Of String) in the Form Load event.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Dim lstWords As New List(Of String)
    Dim tempword As String
    Dim rndm As New Random

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lstWords.AddRange(New String() {&quot;apple&quot;, &quot;orange&quot;, &quot;banana&quot;, &quot;pear&quot;})
    End Sub
&lt;/code&gt;
</pre></p>
<p>When the button to select a word is clicked, we need to select a random word from the List. One point to make is in the Random Next function, the maxValue is<em> exclusive.</em> Meaning, in this example of a List with 4 items, the indexes would be 0 to 3. In order for the Next function to select 3, the maxValue must be 4. Hence the use of the Count property of the List as the maxValue. I frequently see Count -1; likely due to the fact we are used to using Count -1 in a loop so as not to throw an IndexOutOfRange exception. But if Count -1 is used in the Next function, the last item in the List will never be selected.</p>
<p>Here is the code to select a random word:</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
        tempword = lstWords(rndm.Next(0, lstWords.Count))
        lblScrambled.Text = ScrambleWord(tempword)
    End Sub
&lt;/code&gt;
</pre></p>
<p>The Text property of the Label comes from a call to a method named ScrambleWord, which takes the word selected from the List as a parameter.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Function ScrambleWord(ByVal s As String) As String
        Dim sb As New StringBuilder
        Dim chrWord As List(Of Char) = s.ToList
        For i As Integer = 0 To chrWord.Count - 1
            Dim temp As Integer = rndm.Next(0, chrWord.Count)
            sb.Append(chrWord(temp))
            chrWord.RemoveAt(temp)
        Next
        Return sb.ToString
    End Function
&lt;/code&gt;
</pre></p>
<p>First a couple of variables are defined: a StringBuilder (which requires a System.Text imports statement) and a List(Of Char) to hold the character array from the selected word. I use Lists instead of arrays - I find them much easier to work with. Then there is a loop to iterate through the character list. More on this later. Within the loop, we first create an Integer variable and set it&#8217;s value to a random number from 0 to the upper bound of the character List. The character at that index within the List is appended to the StringBuilder. Finally the character at that index is removed from the List. This is what allows each letter to only be selected once.</p>
<p>Now our List has one less item, but because we are using the List.Count &#8211; 1 in the loop, it will continue until all letters have been selected and removed. The final loop occurs when the Count = 1, since the loop will now be 0 to 0. Once the loop is complete, we return the resultant StringBuilder string.</p>
<p>The final block of code is the event for the Button to submit your guess, displaying a MessageBox whether the guess is correct or incorrect.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click
        If tbGuess.Text.Trim = tempword Then
            MessageBox.Show(&quot;Correct&quot;, &quot;Word Guess&quot;, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            MessageBox.Show(&quot;Incorrect&quot;, &quot;Word Guess&quot;, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub
&lt;/code&gt;
</pre></p>
<p>Using a List(Of Char), randomly selecting a character from it, then removing that character from the List is, to me, a much cleaner and more efficient way of scrambling the letters in a word.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/162/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/162/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/162/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=162&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/07/19/letter-scramble/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Collection Except Method</title>
		<link>http://vb2010.wordpress.com/2011/06/19/collection-except-method/</link>
		<comments>http://vb2010.wordpress.com/2011/06/19/collection-except-method/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 19:16:53 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=154</guid>
		<description><![CDATA[In the first part of this article found here I reviewed the Collection Intersect method, explaining why it can be a valuable tool when comparing two collections to find the common items. In this second part, I will show an example of Intersect&#8217;s counterpart (or alter-ego if you prefer), the Collection Except method. This allows you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=154&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the first part of this article found <a title="Collection Intersect vs. For Each Loop" href="http://vb2010.wordpress.com/2011/06/12/collection-intersect-vs-for-each-loop/"> here</a> I reviewed the Collection Intersect method, explaining why it can be a valuable tool when comparing two collections to find the common items. In this second part, I will show an example of Intersect&#8217;s counterpart (or alter-ego if you prefer), the Collection Except method. This allows you to find items in one collection that are not in the other collection.<span id="more-154"></span></p>
<p>The Collection Except method allows you to compare two collections, returning a collection of dissimilar items. Or as stated in the Visual Studio ToolTip for Except:</p>
<p>&#8220;Produces the set difference of two sequences by using the default equality comparer to compare values.&#8221;</p>
<p>When using Except, an easy way to think of what you want to accomplish is:</p>
<p>&#8220;What is in the first collection that is NOT in the second collection?&#8221;</p>
<p>I mention this because that is one difference between Intersect and Except. With Intersect, it doesn&#8217;t matter which order you code the collections: Coll1 to Coll2 and Coll2 to Coll1 will produce the same results. Well, other than the order if they happen to be different between the two collections. The Except method will return the items in the first collection that are not in the second. Therefore, Coll1 to Coll2 can produce different results than Coll2 to Coll1. So be careful in which order you have the collections.</p>
<p>To begin let&#8217;s populate our two ListBoxes with a few names. The list is short to more easily see the results. Since the original Forum post concerned TextBoxes, I&#8217;ve included two of those also. The main reason for this is to point out the Lines collection of the TextBox. I&#8217;ve seen many posts where people split the TextBox Text at the vbCrLf to produce an array of strings. This is unnecessary for the most part.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.AddRange(New String() {&quot;bob&quot;, &quot;john&quot;, &quot;mary&quot;, &quot;rachel&quot;})
        ListBox2.Items.AddRange(New String() {&quot;mary&quot;, &quot;bob&quot;, &quot;greg&quot;})
        ListBox3.Items.AddRange(New String() {&quot;greg&quot;, &quot;rachel&quot;})

        TextBox1.Text = &quot;bob&quot; &amp; vbCrLf &amp; &quot;john&quot; &amp; vbCrLf &amp; &quot;mary&quot; &amp; vbCrLf &amp; &quot;greg&quot; &amp; vbCrLf &amp; &quot;rachel&quot;
        TextBox2.Text = &quot;john&quot; &amp; vbCrLf &amp; &quot;rachel&quot;

    End Sub
&lt;/code&gt;
</pre></p>
<p>Now that we have some data in the controls, let&#8217;s look at the code to compare the collections. There are two Button Click events comparing the ListBox items: one for ListBox1 to ListBox2, and one for ListBox2 to ListBox1, to show how the results will vary depending on the order. The third Click event is for the TextBox Lines collection to show that also.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnLB1toLB2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB1toLB2.Click
        ListBox4.Items.Clear()
        Dim arrDiffLB1toLB2 As IEnumerable(Of String) = ListBox1.Items().OfType(Of String).Except(ListBox2.Items().OfType(Of String))
        ListBox4.Items.AddRange(arrDiffLB1toLB2.ToArray)
    End Sub

    Private Sub btnLB2toLB1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB2toLB1.Click
        ListBox4.Items.Clear()
        Dim arrDiffLB2toLB1 As IEnumerable(Of String) = ListBox2.Items().OfType(Of String).Except(ListBox1.Items().OfType(Of String))
        ListBox4.Items.AddRange(arrDiffLB2toLB1.ToArray)
    End Sub

    Private Sub btnTB1toTB2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTB1toTB2.Click
        TextBox3.Text = &quot;&quot;
        Dim arrDiffTB1toTB2 As IEnumerable(Of String) = TextBox1.Lines.Except(TextBox2.Lines)
        TextBox3.Lines = arrDiffTB1toTB2.ToArray
    End Sub
&lt;/code&gt;
</pre></p>
<p>Now you may have noticed there are three ListBoxes being populated, but only two have been used so far. Here is the reason for the third: you can use Except to compare what was returned between the first two to the third. All in the same line of code.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btn1to2to3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1to2to3.Click
        ListBox4.Items.Clear()
        Dim arrDiffLBAll As IEnumerable(Of String) = ListBox1.Items().OfType(Of String).Except(ListBox2.Items().OfType(Of String)).Except(ListBox3.Items().OfType(Of String))
        ListBox4.Items.AddRange(arrDiffLBAll.ToArray)
    End Sub
&lt;/code&gt;
</pre></p>
<p>Like the Collection Intersect method, Collection Except gives you a nice tool to easily use. It comes in handy to compare two collections and return the items that don&#8217;t match</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/154/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/154/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/154/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=154&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/06/19/collection-except-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
		<item>
		<title>Collection Intersect vs. For Each Loop</title>
		<link>http://vb2010.wordpress.com/2011/06/12/collection-intersect-vs-for-each-loop/</link>
		<comments>http://vb2010.wordpress.com/2011/06/12/collection-intersect-vs-for-each-loop/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 06:14:54 +0000</pubDate>
		<dc:creator>jwavila</dc:creator>
				<category><![CDATA[.NET framework]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://vb2010.wordpress.com/?p=142</guid>
		<description><![CDATA[Most of us are familar with a For Each loop. If you have a WinForms app with any type of collection (List(Of T), array, ListBox Items, etc) there&#8217;s a good chance you have some type of loop, maybe one comparing two collections. Did you know there is a .NET method that has some serious advantages [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=142&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Most of us are familar with a For Each loop. If you have a WinForms app with any type of collection (List(Of T), array, ListBox Items, etc) there&#8217;s a good chance you have some type of loop, maybe one comparing two collections. Did you know there is a .NET method that has some serious advantages over a loop such as this. If you&#8217;d like to learn more, <span id="more-142"></span></p>
<p>A funny thing happened to me on the way to this blog&#8230;I learned something. Two things actually!<br />
After seeing another post in the Forums about comparing lines in a TextBox, I decided to write an article on one of my favorite, but rarely seen, VB.NET methods: Intersect. The next article will discuss it&#8217;s counterpart: Except.</p>
<p>In the thread the OP laid out this situation: there are two multiline TextBoxes, each of which has a list of names from an XML file. The first contained one list, and the second contained a partial list of the first. The question was how to find the names in the first TextBox that were not in the second.</p>
<p>Immediately, the .NET Collection Except method came to mind (which will be covered in the next article). In this article we will review the Intersect method, because that was where I found some startling information. The reason for the discovery was because after posting a solution using Except, I had a thought: &#8220;I wonder if there really is any advantage of one over the other?&#8221;.</p>
<p>In order to compare Intersect over a For Each loop, which others had posted, I created an app with two ListBoxes, each with randomly generated items. The code to populate the ListBoxes, along with the Class level variables used:</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Dim rndm As New Random
    Dim sw As Stopwatch

    Private Sub btnAddData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddData.Click
        For Each lb In Controls.OfType(Of ListBox)()
            lb.Items.Clear()
        Next

        For i As Integer = 1 To 10000
            lbNames1.Items.Add(&quot;A&quot; &amp; rndm.Next(0, 100001))
            lbNames2.Items.Add(&quot;A&quot; &amp; rndm.Next(0, 100001))
        Next
        Debug.WriteLine(&quot;Item count in base collection: &quot; &amp; lbNames1.Items.Count)
    End Sub
&lt;/code&gt;
</pre></p>
<p>I then used the Intersect method in one Button Click event and a loop in another Button Click event. I also added a StopWatch to determine the amount of time each took. I wasn&#8217;t expecting all that much difference &#8211; previously when I&#8217;ve used a loop on a collection with a few dozen items, the results came back almost immediately.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
 Private Sub btnIntersect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIntersect.Click
        lbIntersectItems.Items.Clear()
        sw = New Stopwatch
        sw.Start()
        Dim arrSameLB1toLB2 As IEnumerable(Of String) = lbNames1.Items().OfType(Of String).Intersect(lbNames2.Items().OfType(Of String))
        lbIntersectItems.Items.AddRange(arrSameLB1toLB2.Cast(Of String).ToArray)
        sw.Stop()

        Label1.Text = &quot;Matches: &quot; &amp; lbIntersectItems.Items.Count.ToString &amp; vbCrLf &amp; _
        &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds.ToString
        Debug.WriteLine(&quot;Intersect:&quot;)
        Debug.WriteLine(vbTab &amp; &quot;Matches: &quot; &amp; lbIntersectItems.Items.Count)
        Debug.WriteLine(vbTab &amp; &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds)

        sw.Reset()
    End Sub

    Private Sub btnLoop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoop.Click
        lbLoopItems.Items.Clear()
        sw = New Stopwatch
        sw.Start()
        For Each s As String In lbNames1.Items
            If lbNames2.Items.Contains(s) Then
                lbLoopItems.Items.Add(s)
            End If
        Next

        sw.Stop()

        Label2.Text = &quot;Matches: &quot; &amp; lbLoopItems.Items.Count.ToString &amp; vbCrLf &amp; _
        &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds.ToString
        Debug.WriteLine(&quot;Loop:&quot;)
        Debug.WriteLine(vbTab &amp; &quot;Matches: &quot; &amp; lbLoopItems.Items.Count)
        Debug.WriteLine(vbTab &amp; &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds)
        sw.Reset()
    End Sub
&lt;/code&gt;
</pre></p>
<p>And with each ListBox containing 100 items, that was pretty much the case. However as I increased the number of items in each ListBox, the time difference grew substantially.</p>
<p>Here is a breakdown of the times (in milliseconds) to run each (note that I ran each 5 times, except the 100,000, which I only ran 3 times):</p>
<p>.                                        Intersect                       Loop</p>
<p>.                          Range(ms)      Avg(ms)        Range(ms)     Avg(ms)</p>
<p># Items</p>
<p>100            .               1-1                 1                         2-5                 3</p>
<p>1000         .               2-2                2                      28-36             33</p>
<p>10000      .             34-47            40                 2099-2180      2134</p>
<p>100000   .           189-197          193                       ???               ??</p>
<p>As you can see, with only 100 items, both were comparable in average elapsed time. And even at 1000 items, while there is the beginning of a separation, an average of 33 ms for the loop is not a problem. However, once you get to 10,000 items, there is a significant difference: 40 ms for Intersect versus 2134 ms for the loop. Then at 100,000 items, Intersect still came in at a respectable 193 ms (substantially faster than the loop using 10,000 items). There are no times for the loop using 100,000 items because my app became unresponsive while running it, and after 3 tries at it and failing each time, I gave up.</p>
<p>That was my first interesting discovery &#8211; the time difference. The second came about because I noticed the number of matches being displayed in the labels were different. For example, in the 10,000 item test, if Intersect displayed 900 matches, the loop displayed 950. At first I was confused, then I thought &#8220;maybe Intersect is not only reporting the matches, but the distinct matches!&#8221;. To test this, I then added a LINQ query to the items returned from the loop and compared that number  to Intersect. And guess what? They were the same.</p>
<p><pre class="brush: vb;">
&lt;code&gt;
Private Sub btnLoopDist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoopDist.Click
        lbLoopItemsDistinct.Items.Clear()
        sw = New Stopwatch
        sw.Start()
        For Each s As String In lbNames1.Items
            If lbNames2.Items.Contains(s) Then
                lbLoopItemsDistinct.Items.Add(s)
            End If
        Next
        Dim distitem = ((From d In lbLoopItemsDistinct.Items).Distinct().ToArray).Count

        sw.Stop()

        Label3.Text = &quot;Matches: &quot; &amp; distitem.ToString &amp; vbCrLf &amp; _
        &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds.ToString
        Debug.WriteLine(&quot;Loop w/ Distinct:&quot;)
        Debug.WriteLine(vbTab &amp; &quot;Matches: &quot; &amp; distitem)
        Debug.WriteLine(vbTab &amp; &quot;Elapsed: &quot; &amp; sw.ElapsedMilliseconds)

        sw.Reset()
    End Sub
&lt;/code&gt;
</pre></p>
<p>So not only is Intersect much faster the greater the number of items being compared, but it throws in a Distinct query also, free of charge.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vb2010.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vb2010.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vb2010.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vb2010.wordpress.com&amp;blog=8118831&amp;post=142&amp;subd=vb2010&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://vb2010.wordpress.com/2011/06/12/collection-intersect-vs-for-each-loop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe826f5b2f2729e94d893c92b0fe8b8a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">jwavila</media:title>
		</media:content>
	</item>
	</channel>
</rss>
