Using Timer in VB.Net
Building an Electronic Clock in VB.Net using timer class
(VB.NET ProgressBar using Timer)
Public Class Form1
Dim t As New Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
t.Interval = 1000
AddHandler t.Tick, AddressOf Me.t_ShowProgress
AddHandler t.Tick, AddressOf Me.t_ShowTime
t.Start()
End Sub
Private Sub t_ShowProgress()
ProgressBar1.Value += 10
If ProgressBar1.Value = 100 Then
ProgressBar1.Value = 0
End If
End Sub
Private Sub t_ShowTime()
Label1.Text = Now
End Sub
End Class
Add Handler – Associates an event with an event handler at run time. The Handles keyword and the AddHandler statement both allow you to specify that particular procedures handle particular events, but there are differences. The AddHandler statement connects procedures to events at run time. Use the Handles keyword when defining a procedure to specify that it handles a particular event.
The Tick event (this is similar to Visual Basic Timer1_Timer event) occurs when the specified timer interval has elapsed and the timer is enabled. This is based on the interval set for the Timer (1000 ms or 1 sec here)
The progress bar will be reset after it reaches 100. The timer will run till the form is closed. Since the process is synchronous only the timer event will be executed or the label will be updated. The same can also be achieved async
Regular Expressions in Dot Net (.NET)
Finding Duplicate Words in a String using .NET Regular Expressions
Regular Expressions (REGEX) does wonders in programming. Here is a simple Regex code that identifies duplicate words like ‘the the’, ’something something’ etc. Probably copyeditors can use this code to do the work that Microsoft Spell check does
Sub Regex_Checker_Duplicate_Words()
Dim oRegex As Regex
Dim sPattern As String
Dim oMatches As Match
Dim sText As String
sText = ” the the category catastropic cat cat and rat b b “
sPattern = “\b([a-zA-Z]+)\s+\1″
oRegex = New Regex(sPattern)
oMatches = oRegex.Match(sText, sPattern)
While oMatches.Success
MsgBox(oMatches.Groups(0).Value.ToString)
oMatches = oMatches.NextMatch
End While
End Sub
Returns a new Match with the results for the next match, starting at the position at which the last match ended (at the character beyond the last matched character).







