Even or Odd Number in VB.NET

Submitted by: 
Visitors have accessed this post 29565 times.

Even Numbers are any integer that can be divided exactly by 2. The last digit will be 0, 2, 4, 6 or 8. If it is not an even number, it is called an odd number. The last digit will be 1, 3, 5, 7 or 9.

In this tutorial, we will create a program that can determine a number whether odd or even.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add only one Button named Button1 and labeled it as "Determine if Odd or Even Number". Insert also Textbox and named it as Textbox1 for inputting the desired number. You must design your interface like this:

design

3. Now put this code for your code module. This code is for Button1_Click:

Public Class Form1

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim Mynumber As Integer
  3. Dim isEven As Boolean
  4. Mynumber = Val(TextBox1.Text)
  5. If Mynumber Mod 2 = 0 Then
  6. isEven = True
  7. MsgBox("The number " & " " & Mynumber & " is an even number")
  8. Else
  9. MsgBox(Mynumber & " " & "is an Odd number")
  10. End If
  11.  
  12. End Sub
  13. End Class

Explanation:

We initialized variable Mynumber as Integer to hold the value inputted in textbox1. The main reason to get the even number is to get their value as divisible by 2 that is equal to zero. So that is why we used the Mod function. Mod Operator divides two numbers and returns only the remainder. The number inputted in textbox1 was divided by 2 and if the remainder is zero then we considered it as an even number. Otherwise, it is an odd number in our If-Else statement.

Output:

outputoutput

Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.