Even Or Odd Number

Determine Even or Odd Number in VB.NET

Details: Even Or Odd Number

This tutorial focuses on how to determine even or odd numbers using VB.NET. Even Numbers can be defined as integers that can be divided by 2, the last digit can be 0,2,4,6, or 8. When a number(s) is not even, it is called an odd number that has last digits of 1,3,5,7, or 9.

This program is developed to establish if a number is even of odd.

Procedure: Even Or Odd Number

  1. We should begin with making a Windows Form Application for this instructional exercise by following the given steps in Microsoft Visual Studio: Go to File, click New Project, and select Windows Application.
  2. Then, add just a single Button named Button1 and label it “Determine Odd or Even Number”. Input Textbox and name it Textbox1 for inserting the ideal number. You should plan your point of interaction like this.
  3. You can now copy and paste the code below for your code module. The given code is for the functionality of “Button1_Click”.

Button Click Function Code: Even Or Odd Number

					Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Mynumber As Integer
    Dim isEven As Boolean
    Mynumber = Val(TextBox1.Text)
    If Mynumber Mod 2 = 0 Then
        isEven = True
        MsgBox("The number " & " " & Mynumber & " is an even number")
        MsgBox(Mynumber & " " & "is an Odd number")
    End If
End Sub

We introduced the variable “Mynumber” as an Integer to hold the value inputted in “textbox1”. The principal motivation to get the even number is to get their value as divisible by 2 which is equivalent to zero. So for that reason, we utilized the Mod function. Mod Operator divides two numbers and returns the remainder. The number inputted in textbox1 was divided by 2 and if the rest is zero, we consider it as an even number. In any case, it is an odd number in our If-Else statement.

Determine Even or Odd Number, vb.net, source code, free download, free script, visual basics, free vb tutorial

Don’t forget to share this post!

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Article