Browse by Tags
All Tags »
FP-Tutorial-VB (RSS)
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
Read More...
[Table of Contents] [Next Topic] [Blog Map] The following code is attached to this page. Imports System.IO Imports System.Xml Imports System.Text Imports DocumentFormat.OpenXml.Packaging Public Class GroupOfAdjacent( Of TElement, TKey) Implements IEnumerable(
Read More...
[Table of Contents] [Blog Map] If you finished this tutorial, feel free to add a comment on this page. 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,
Read More...
[Table of Contents] [Next Topic] [Blog Map] 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
Read More...
[Table of Contents] [Next Topic] [Blog Map] 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: Dim groupedCodeParagraphs = paragraphsWithText _ .GroupAdjacent(
Read More...
[Table of Contents] [Next Topic] [Blog Map] We need one more query to retrieve the comments: Dim defaultStyle As String = _ CStr ( _ ( _ From style In styleDoc.Root _ .Elements(w + "style" ) _ Where ( _ CStr (style.Attribute(w + "type" )) = "paragraph"
Read More...
[Table of Contents] [Next Topic] [Blog Map] 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: Public Function GetParagraphStyle(para
Read More...
[Table of Contents] [Next Topic] [Blog Map] 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
Read More...
[Table of Contents] [Next Topic] [Blog Map] 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
Read More...
[Table of Contents] [Next Topic] [Blog Map] Attached to this page is the source Open XML word document that contains the paragraphs styled as Code. The document looks like this: Following is the XML for the main document part. You can see the body of
Read More...
[Table of Contents] [Next Topic] [Blog Map] An easy way to see the XML in the parts of a WordprocessingML document is to create one in your word processor, save it, and then run the following program that prints the XML to the console. You can also rename
Read More...
[Table of Contents] [Next Topic] [Blog Map] Open XML Packages To follow this tutorial, you don't need to delve into all of the details of working with packages. This topic presents a small chunk of code that you can use as boilerplate code – it opens
Read More...
[Table of Contents] [Next Topic] [Blog Map] Our first goal is to retrieve all paragraphs in the document, along with the style of the paragraph. To review, all paragraphs are children of the "body" element, and have a tag of "w:p". If the style of the
Read More...
[Table of Contents] [Next Topic] [Blog Map] We're now ready to talk more about some of the core FP concepts. Declarative vs. Imperative Code Imperative languages are state based. Object-oriented programming languages such as C#, C++, and Java have extensive
Read More...
[Table of Contents] [Next Topic] [Blog Map] The first problem that we're going to tackle is to retrieve some specific text out of an Open XML Word document. In this word document will be text that has the style of "Code". We want to find all consecutive
Read More...