Online Programming Tutorials

and in VB – Arithmetic Operators

Posted on: Sep 14, 2011 by admin 1 Comment

What is arithmetic operators? How can it be use in programming? Why do we have to use arithmetic operations in programming?
Arithmetic operators are operators that are being use to perform arithmetic calculations such as adding, subtracting, multiplying or dividng a particluar problem. There are many various ways that arithmetic can be use for. Arithmetic can also be use in our daily life activities. Also we have to use arithmetic operators in programming whether it will be a web based or desktop programming. But in this article, we will going to use Visual Basic (VB) for us to be more familiar with VB programming language. In programming we did not only make websites and application but also we perform calculations. Sample of an applications that we use calculations are calculators, enrollment systems, cashiering systems, inventory systems and etc. There are also many ways on how to apply arithmetic in programming. This allows the program to perform calculations to make the process more faster. It is use in programming especially when we are dealing with mathematical problems or a sort of analytical problems that involved solving and analysis. We have to use arithmetic operations in programming so that we can fulfill the goal that we want to achieve. But many are confused about what are the different types of arithmetic operators? How to use them? Below are the list of operators that we can use in programming.

Operators

Funtions

Example

+

Addition 2+2=4

-

Subtration 4-3=1

*

Multiplication 4*2=8

/

Division 4/2=

ˆ

Exponential 2ˆ2=4

 

This are the list of arithmetic operators that can be use in programming. This are also the most and commonly use operators in every programming problems. To understand fully how does it work in VB then a sample code below is provided.

Sample Code:

Addition:


Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click

        Dim val1, val2 As Single
        Dim sum As Integer

        val1 = num1.Text
        val2 = num2.Text

        sum = val1 + val2

        lblresult.Text = sum

End Sub

Output:

addition in VB

 

 

 

 

 

 

 

Subtraction


Private Sub btn_subtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_subtract.Click
        Dim res As Integer
        res = num1.Text - num2.Text
        lblresult.Text = res
    End Sub

Output:

 

subtraction in VB

 

 

 

 

 

 

 

Multiplication


Private Sub btn_multiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_multiply.Click
        Dim res As Integer
        res = num1.Text * num2.Text
        lblresult.Text = res
    End Sub

Output:

multiplication in VB

 

 

 

 

 

 

 

Division


Private Sub btn_divide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_divide.Click
        Dim diff As Integer
        If (num1.Text < num2.Text) Then
            lblerrormessage.Text = "Num1 must be greater than num2!"
            num1.Text = ""
            num2.Text = ""
            lblresult.Text = ""
        Else
            diff = num1.Text / num2.Text
            lblresult.Text = diff

        End If
    End Sub

Output:

division in VB

 

 

 

 

 

 

 

If there is some problem or questions regarding with this article, just CLICK THIS LINK to be redirected to the forum page. THANK YOU.

Tags: ,


One Response

  1. I don’t even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you’re going to a famous blogger if you are not already ;) Cheers!

Leave a Reply