Even or Odd in Visual Basic

Introduction: This tutorial is on how to create a simple tool in Visual Basic to check whether the entered number is even or odd. Design: For this program, we need a couple of components; Button, button1, Begin the checking process. NumericUpDown, numericUpDown1, Hold the number value. Button Click: Once the button is clicked, we first want to create a new integer variable and set it equal to the value of the numericupdown control...
  1. Dim num As Integer = numericUpDown1.Value
Next we want to write a simple if statement using the MOD operator to see if the integer variable, MOD 2, is true or not. If it is, the number is even, otherwise it is false...
  1. If ((num Mod 2) = 0) Then
  2. MsgBox("Even")
  3. Else
  4. MsgBox("Odd")
  5. End If
Finished!

Comments

Submitted byPradum Shukla (not verified)on Mon, 01/09/2023 - 21:58

Private sub oddbtn_class() Dim num As Integer num = Val(text1.text) If(num Mod 2=0) Then Msgbox("Even number") Else Msgbox("Odd Number") End if End sub

Add new comment