Translate

Friday 31 May 2013

Arithmetic Operators Example in VB.NET


Programming Examples using Arithmetic Operations

In this Blog we will some programs using arithmetics operations. So far we saw assigning values to variable and calculate and display result. Assigning values to variables called 'Constants' i.e., the values do not change during execution of a program. Now we are going to see how to set or assign values to vairables during execution.

Module Example3
    Sub Main()
        Dim Num1, Num2 As Integer
        Dim AddResult, SubResult, DivResult, MulResult As Integer
        Console.WriteLine("Enter Value for Num1: ")
        Num1 = Console.ReadLine()
        Console.WriteLine("Enter Value for Num2: ")
        Num2 = Console.ReadLine()

        AddResult = Num1 + Num2
        SubResult = Num1 - Num2
        DivResult = Num1 / Num2
        MulResult = Num1 * Num2

        Console.WriteLine("Results of Arithmetic Operations.....")

        Console.WriteLine("Addition Result: " & AddResult)
        Console.WriteLine("Subtraction Result: " & SubResult)
        Console.WriteLine("Divison Result: " & DivResult)
        Console.WriteLine("Multiplication Result: " & MulResult)

        Console.WriteLine(".............End......................")
        Console.ReadKey()

    End Sub
End Module

 The above programiming  examples shows how to get input duing runtime and shows the output you have seen that In the Console.WriteLine I have used '&' (Ampersand)  this actually concatenate two string or two words. i.e., it concatenate AddResult  with 'Addition Result:' type and run the program you will notice it.


We will see more examples in the next blog.

Tuesday 28 May 2013

Arithmetic Operator and Assignment Operator in VB.NET

Introduction to VB.NET Programming II

In the previous blog we one datatype and variable now we will see operators in VB.NET.

First we will see Arithmetics Operators and Assignment Operator.

Arithmetic Operators

Addition  : +
Subtraction : -
Multiplication : *
Division : /


Assignment Operator

Equal : =


We will see example programs  of these operators.

Example Program-2

Module Example2
  Sub main()
  Dim Num1, Num2 As Integer
  Dim AddResult, SubResult, DivResult, MulResult As Integer
  Num1 = 100
  Num2 = 25
 
  AddResult= Num1 + Num2
  SubResult= Num1 - Num2
  DivResult= Num1 / Num2
   MulResult = Num1 * Num2
 
  Console.Writeline("Addition : " &AddResult)
  Console.Writeline("Subtraction : " &SubResult)
  Console.Writeline("Division : " &DivResult)
  Console.Writeline("Multiplication : " &MulResult )
 
  Console.ReadKey()

  End SubEnd ModuleIn the above program  we declared two variable for assigning Values and four variables for getting result of four arithmetic operations and the results are displayed on the screen.   Console.Writeline function display output and goes to next line the difference between Console.Write and Console.Writeline is first one display output and does not go to next line but the later one display output and moves to next line.
We will see more examples using Arithmetic operators in the next blog.       
       

       








Monday 27 May 2013

Programming using VB.NET For Kids

Introduction to VB.NET Programming



Let us see the some basic programming language requirement.

1. Data type
2. Variables
3. Controls Structure


Datatype defines the type of data going to use.

Variables allocate the memory to store values based on datatype.

Control structure will be discussed later.


 Let see the datatype called 'Integer'.  Integer datatype stores whole number values ie., numbers without fraction.  It has capacity to store value range from –2,147,483,648 to +2,147,483,647 .
Other datatypes will be discussed as needed.

First open Visual Studio Express Edition or orther Visual Studio edition , select New Project -> Visual Basic-> Console Application. Name it Example1 Click Ok.

Below is a example program type it down.

Example Program-1

Module Example1

Sub Main()

  Dim A As Integer
  A = 123
  Console.Write(A)
  Console.ReadKey()
End Sub

End Module
 

 

 

The above program  first declares a variable A of datatype Integer, and it is assigned a value 123. The next statement Console.Write(A) displays the value of A to the screen and next Console statement is waiting for get a key to close the screen.

We will see more on next blog.