Sunday, January 18, 2004

Regular Expressions Example

At some point everyone has written code to test values that match patterns. There are many different ways this can be done. Typical examples, include string handling or using the myriad of other algorithms available. Recently, I have been working the Regular Expressions available within .NET. I am pretty impressed with their simplicity and power. The downside is that many times they can be quite the mental puzzle to figure out. I can easily understand how these can be overwhelming to understand and use. Over the next couple of weeks, I am planning on blogging about some of these that I have been playing with and collecting.

 

Here is a simple example that checks to see if a string contains a specific phrase:

 

Imports System.Text.RegularExpressions

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim r As Regex = New Regex("(\w+)\s+(blue)")

        Dim comstring As String = "blue ball"

 

        If r.IsMatch(comstring) Then

            MsgBox("Match Successful")

        Else

            MsgBox("Match failed")

        End If

 

    End Sub

 

Keep an eye out for additional ones that I will post. If you have any examples that you want to add – email me with any samples you may have and want posted.


10:07:12 PM    
comment [] trackback []

InfoPath and the DataSet

Unfortunately, InfoPath is not able to directly consume a Web Service that returns an ADO.NET DataSet. InfoPath is designed to handle generic XML payloads. By default, a DataSet that is returned by a Web Service is a serialized XML string that returns a format that InfoPath is not able to directly consume.

 

If you are like me, I use the DataSet as the base for everything I do around data access. I developed this little helper function that I use to convert a DataSet to an XML Document that InfoPath is able to understand.

 

<WebMethod()> Public Function InfoPathGetRequests(ByVal RequestedStatus

 As Boolean) As System.Xml.XmlDataDocument

' this is a wrapper service for conversion of the DataSet for use

' in an InfoPath form

 Dim requestds As DataSet

 ' call the Web Service to get the DataSet

 requestds = GetRequests(RequestedStatus:=RequestedStatus)

 ' create the XML Document

 requestds.Namespace = "Http://localhost/RequestType"

 Dim Info As System.Xml.XmlDataDocument = New  _     

            System.Xml.XmlDataDocument(requestds)

 Return Info

 

End Function

 

I then point my InfoPath form at this Web Service function and off it goes!


9:31:37 PM    
comment [] trackback []

Debugging an InfoPath form

Today all code in InfoPath is written using the Microsoft Script Editor (MSE). The problem is that if you attempt to set breakpoints within MSE they are ignored. This can be rather frustrating for those that are new to InfoPath. In order to enter debug mode using InfoPath you need to place either a debugger (JavaScript) or stop (VBScript) statement inline. When hit this provides the ability to attach to the InfoPath process and enter debug mode.


9:00:44 PM    
comment [] trackback []