Duane

Duane

  • NA
  • 77
  • 0

Pattern matching in a textbox

Feb 15 2013 8:32 PM
I am trying to accomplish the following:
Read the contents of a textbox and look for a pattern match, then execute a series of events when (or if) that pattern is found.
That much I have accomplished, but how do I get the program to look for other instances of that pattern within the same textbox.
For instance, suppose the program finds a match at index 0 in the textbox, then executes its series of events. How do I get a recursion
of the text while ignoring the text section previously covered.

Imports SpeechLib
Imports System.Text.RegularExpressions
Public Class Form1
    Dim compVoice As New SpVoice
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim regex As Regex = New Regex("^\d\d:\d\d")
        Dim td As DateTime = DateTime.Now()
        If CInt(TextBox1.Text) = td.Day Then
            'run textbox1 here.
            If regex.IsMatch(txtDay1.Text, 0) Then
                compVoice.Volume = 100
                compVoice.Speak("Warning")
                compVoice.Volume = 50
                compVoice.Speak(txtDay1.Text.Substring(6))
            Else
                compVoice.Speak("No text present.")
            End If
        ElseIf CInt(TextBox2.Text) = td.Day Then
            'run textbox2 here
            If regex.IsMatch(txtDay2.Text, 0) Then
                compVoice.Volume = 100
                compVoice.Speak("Warning")
                compVoice.Volume = 50
                compVoice.Speak(txtDay2.Text.Substring(6))
            Else
                compVoice.Speak("No text present.")
            End If
        ElseIf CInt(TextBox3.Text) = td.Day Then
            If regex.IsMatch(txtDay3.Text, 0) Then
                compVoice.Volume = 100
                compVoice.Speak("Warning")
                compVoice.Volume = 50
                compVoice.Speak(txtDay3.Text.Substring(6))
            Else
                compVoice.Speak("No text present.")
            End If
        Else
            Exit Sub
        End If
    End Sub
End Class

Answers (1)