Calculate Age Between Two Ages in VB.NET

In this article, I will discuss how to calculate age between two ages.
  • 2477

Introduction

In this article, I will discuss how to calculate age between two ages. In this i have taken two LabelBox , two TextBox and one Button. LabelBox is used to display something, it can be display by setting properties from the properties window which you want to display. TextBox is used to accept user input on a Form. Button is used to show the output when we click on it. In this i have use validation also which is used to put limit on any TextBox. In this if we enter a age more than two digit then it will show invalid value. Following are the steps to be followed.

Step1: Open the visual Studio 2010.

Step2: Click on new project and select category Windows in VB.

Step3: Do the following coding on the main page i.e Form1.vb.

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  If True Then
            Dim age1 As Integer = Convert.ToInt32(TextBox1.Text)
            Dim age2 As Integer = Convert.ToInt32(TextBox2.Text)
            Dim result As Integer
            result = TextBox1.Text - TextBox2.Text
            If Convert.ToInt32(result) >= 50 Then
                MessageBox.Show("Invalid Input"
Else
                MessageBox.Show("The result of the calculation is" & result)

             End If
        End If
    End Sub

    Private Sub Check_valid(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
  If (Convert.ToInt32(TextBox1.Text) > 100) Then
           Label1.Text = "invalid value"
 End If
    End Sub
End Class

Press f5 the output for the code will be display like this.

1.jpg
 

When we insert value 50 and 15 it will display the output this.

2.jpg

When we insert value 80 and 15 it will show invalid input because we select the range of the result less than 50.

3.jpg

If we insert value more than 100 in Label1 then it will show invalid value because i have applied validation on Label1.

4.jpg
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.