Functional Programming Tutorial for Visual Basic 9.0

Visual Basic 9.0 added many language features that allow us to write in the functional style in a natural and expressive way.  The value of programming in the functional style has been apparent to me for some time.  VB developers can realize the benefits of functional programming, so I’ve written a tutorial for VB developers:…


Complete Listing of ParseWordML – VB

[Table of Contents] [Next Topic] The following code is attached to this page. This blog is inactive.New blog: EricWhite.com/blog Blog TOC Imports System.IOImports System.XmlImports System.TextImports DocumentFormat.OpenXml.Packaging Public Class GroupOfAdjacent(Of TElement, TKey)    Implements IEnumerable(Of TElement)     Private _key As TKey    Private _groupList As List(Of TElement)     Public Property GroupList() As List(Of TElement)        Get            Return _groupList        End Get        Set(ByVal value…


Conclusion – VB

[Table of Contents] If you finished this tutorial, feel free to add a comment on this page. This blog is inactive.New blog: EricWhite.com/blog Blog TOC In the end, I believe that programming in the FP style is useful and powerful.  When programming, it enables you to focus more on the problem domain, and focus less…


Filtering Out the Groups that we Don’t Want – VB

[Table of Contents] [Next Topic] We are not interested in the groups that don’t contain code, so let’s get rid of them.  To do this, we simply tack a call to the Where operator on the end: This blog is inactive.New blog: EricWhite.com/blog Blog TOC Dim groupedCodeParagraphs = paragraphsWithText _    .GroupAdjacent(Function(p) p.Style) _    .Where(Function(g) g.Key…


Retrieving the Two Code Groups – VB

[Table of Contents] [Next Topic] There are two groups of paragraphs in our document that are styled as “Code”.  The first group contains the C# code that we want to test.  The second group contains a single paragraph that is the output of the code in the first group.  Next in the process of formulating…


The Final Results – VB

[Table of Contents] [Next Topic] We need one more query to retrieve the comments: This blog is inactive.New blog: EricWhite.com/blog Blog TOC Dim defaultStyle As String = _    CStr( _            ( _                From style In styleDoc.Root _                    .Elements(w + “style”) _                Where ( _                    CStr(style.Attribute(w + “type”)) = “paragraph” And _                    CStr(style.Attribute(w + “default”)) =…


Refactoring using a Pure Function – VB

[Table of Contents] [Next Topic] It would be useful to refactor this example to clean up the code that determines the style of the paragraph. We can make a function that has no side effects that returns the style name: This blog is inactive.New blog: EricWhite.com/blog Blog TOC Public Function GetParagraphStyle(para As XElement) As String   …


Retrieving the Default Style Name from the Styles Part – VB

[Table of Contents] [Next Topic] There is a problem in the example presented in the previous topic, which is that it sets the Style property of the anonymous type to null if there is no style on the paragraph.  This is incorrect; we should use another query to find the default style in the styles…


Retrieving the Text of the Paragraphs – VB

[Table of Contents] [Next Topic] Our next goal is to retrieve the text of the paragraphs in the document. Text is stored in the “t” nodes that are contained in “r” nodes that are children of the paragraph node. Text may be broken up into multiple “t” nodes, so we have to concatenate all of…


Retrieving the Paragraphs – VB

[Table of Contents] [Next Topic] Our first goal is to retrieve all paragraphs in the document, along with the style of the paragraph. This blog is inactive.New blog: EricWhite.com/blog Blog TOCTo review, all paragraphs are children of the “body” element, and have a tag of “w:p”.  If the style of the paragraph is other than…