Tuesday, October 10, 2017

Odd and Even Number Checker in Visual Basic

In this article I would like to share with you a sample program that will ask the user to give a number and then our program will check if the given number is an odd or even number using Visual Basic. I also included a function to check if the text box is empty and it will display a message box to give a warning to our user. The code is very simple and easy to understand. I hope you will find my work useful. Thank you.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

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


Function IsOdd(ByVal iNum As Integer) As Boolean
    IsOdd = ((iNum \ 2) * 2 <> iNum)
End Function

Private Sub Command1_Click()

If Text1.Text = "" Then
MsgBox ("Cannot be empty")
Text1.Text = ""
Label1.Caption = ""
Text1.SetFocus
Exit Sub
End If

If IsOdd(Val(Text1.Text)) = True Then
Label1.Caption = "The given number " & Text1.Text & " is an ODD number."
Else
Label1.Caption = "The given number " & Text1.Text & " is an EVEN number."
End If

End Sub

Private Sub Command2_Click()
Text1.Text = ""
Label1.Caption = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()
End
End Sub




No comments:

Post a Comment