How to minimize reusing the same code

B&W

B&W

Soldato
Joined
3 Oct 2003
Posts
7,668
Location
Birmingham
Hi I'm pretty hopeless at VB, basically I have lots of similar code in my program.

I'm pretty sure there must be a way to minimize the repeating of the same code.

The main culprits are two subs with If statements.

Code:
Private Sub ValidateData()

        Dim data As Boolean

        data = IsNumeric(txttemp.Text)

        If data = False Then
            MessageBox.Show("Temp Data is invalid")
            txttemp.Text = ""

        End If

        data = IsNumeric(txtheartrate.Text)

        If data = False Then
            MessageBox.Show("Heart Rate Data is invalid")
            txtheartrate.Text = ""

        End If


Code:
Private Sub paddy()

        If txttemp.TextLength < 4 Then
            txttemp.Text = txttemp.Text.PadLeft(4, "0")

        End If

        If txtheartrate.TextLength < 3 Then
            txtheartrate.Text = txtheartrate.Text.PadLeft(3, "0")

        End If
 
Back
Top Bottom