Friday, April 14, 2017

Square a Number Using Visual Basic NET


In this article I would like to share with you guys a simple program that will ask the user to give a number and then our program will convert the given number into its square number equivalent. I wrote this code using Microsoft Visual Basic NET 2013. I added an error checking for empty text box value.  I hope you will find my work useful thank you very much.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Public Class Form1
    Function Square(ByVal y As Integer) As Integer
        Return y ^ 2
    End Function

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        End
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim a, solve As Integer
        Dim b As String

        a = Val(TextBox1.Text)

        solve = Square(a)

        If TextBox1.Text = "" Then
            MessageBox.Show("Sorry can't be empty.")
            TextBox1.Focus()

        Else
            Label2.Text = "The square value of " & a & " is " & solve & "."
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label2.Text = ""
        TextBox1.Focus()
    End Sub
End Class



No comments:

Post a Comment