Translate

Tuesday 2 July 2013

Logical Operator And in Visual Basic.NET




 In this blog we will see Logical operator 'And ' in If Else Statement. Let us see an example progam using 'And' Operator.



 Module Example14
    Sub Main()
        Dim age As Integer
        Dim gender As String
        Console.WriteLine("Enter Your Age:")
        age = Console.ReadLine()
        Console.WriteLine("Enter your Gender M/F:")
        gender = Console.ReadLine
        If age >= 65 And gender = "M" Then
            Console.WriteLine("Senior Citizen Male")
        End If
        Console.ReadKey()
    End Sub
End Module

The above example shows use of  'And' operator.  If both age and gender  conditions are true then statements follows this condition will execute otherwise not.

Monday 17 June 2013

Skip numbers to generate Odd Numbers


In the previous blogs we discussed about For loop and examples using it. Now we will see how to skip  numbers to generate Odd number  in for Loop.


Module Example13
    Sub main()
        Dim i As Integer
        For i = 1 To 25 Step 2
            Console.WriteLine(i)
        Next
        Console.ReadKey()
    End Sub
End Module

The above example shows how to generate Odd numbers just by adding Step keyword with For loop.

Next we will see another example to generate numbers in descending order.

Module Example14
    Sub main()
        Dim i As Integer
        For i = 25 To 1 Step -1
            Console.WriteLine(i)
        Next
        Console.ReadKey()
    End Sub

End Module

Thursday 13 June 2013

For Loop Example Program


Let us see an example program using for loop . This example show how to add sequence numbers using for loop.

Module Example12
    Sub main()
        Dim StartNum, EndNum As Integer
        Dim sum As Integer = 0
        Console.Write("Enter Start Number:")
        StartNum = Console.ReadLine()
        Console.Write("Enter End Number:")
        EndNum = Console.ReadLine()
        For I As Integer = StartNum To EndNum
            sum = sum + I
        Next
        Console.WriteLine("Sum of " & StartNum & " to " & EndNum & " is :" & sum)
        Console.ReadKey()
    End Sub

End Module
The above Example add numbers from StartNum to EndNum  and produce sum of these sequence  numbers.



Wednesday 12 June 2013

For Loop in VB.NET

In this Blog I will show you loop. If want to do an action repeatedly you can use loop. VB.NET have 3 types of loop first we will see For loop in this blog other two loops will see later.


 Module Example11
    Sub main()
        Dim val As Integer
        For val = 1 To 10
            Console.WriteLine(val)
        Next
        Console.ReadKey()
    End Sub
End Module

The above example shows how For loop is used to display numbers from 1 to 10 the value starts from 1 displays using Console.Writeline statement  and moves to Next statement the next statement increase the val from 1 to 2 likewise it keeps on increasing the val  by 1 if the val reaches 11 the loop finishes and Console.Readkey() will execute.

Monday 10 June 2013

Select Case In VB.NET

In this blog we will see alternate to If Else If  Structure i.e Select Case statement

Syntax

Select Case  Text Expression

Case  Expression1
Statment1

Case Expression2
Statement2

Else
Statement
End Select

Let us see an example using Select Case Statement.
Module Example10

    Sub Main()
        Dim MonthNum As Integer

        Console.WriteLine("Enter Month Name:")
        MonthNum = Console.ReadLine()

        Select Case MonthNum
            Case 1
                Console.WriteLine("January")
            Case 2
                Console.WriteLine("February")
            Case 3
                Console.WriteLine("March")
            Case 4
                Console.WriteLine("April")
            Case 5
                Console.WriteLine("May")
            Case 6
                Console.WriteLine("June")
            Case 7
                Console.WriteLine("July")
            Case 8
                Console.WriteLine("August")
            Case 9
                Console.WriteLine("September")
            Case 10
                Console.WriteLine("October")
            Case 11
                Console.WriteLine("November")
            Case 12
                Console.WriteLine("December")
            Case Else
                MsgBox("Invalid Input")
        End Select
        Console.ReadKey()
    End Sub

End Module

The above example is rewriteen of If Else If Example. You can use If Else If  or Select Case nothing is difference in performance.





Saturday 8 June 2013

Get Month Name Example using VB.NET


Get Month Name

 This blog shows an example how to get month name by entering month no in VB.NET

Module Example9
    Sub main()
   Dim MonthNum As Integer
  Console.Write("Enter a Month Number 1-12 :")
  MonthNum = Console.ReadLine()
If MonthNum = 1 Then
            Console.WriteLine("January")
Else If MonthNum = 2 Then
           Console.WriteLine(" February ")
 Else If MonthNum = 3 Then
           Console.WriteLine(" March")
 Else If MonthNum = 4 Then
           Console.WriteLine(" April ")
 Else If MonthNum = 5 Then
           Console.WriteLine(" May ")
 Else If MonthNum = 6 Then
           Console.WriteLine(" June ")
 Else If MonthNum = 7 Then
           Console.WriteLine(" July")
 Else If MonthNum = 8 Then
           Console.WriteLine(" August ")
 Else If MonthNum = 9Then
           Console.WriteLine(" September ")
 Else If MonthNum = 10 Then
           Console.WriteLine(" October ")
 Else If MonthNum = 11 Then
           Console.WriteLine(" November ")
 Else If MonthNum = 12 Then
           Console.WriteLine(" December ")

 Else
 Console.WriteLine("Invalid Input")
        End If
    End Sub
 End Module

The above example is same as getting day name by entering day number which we have seen in previous blog

Friday 7 June 2013

Nested If Else in VB.NET with Get Day Name Example



Nested If Else

In this blog we are going to see Nested If Else in VB.NET. Let us see the syntax


If Condition1 Then
Statements
Esle If Condition2 Then
Statements
Else If Condition3 Then
Statements
Else
Statements
End If

The above syntax first check the If Condition1 if it is true the statements followint the Condition1 will be executed and goes to End if , If it is false then check the Condition2 and it is true then Statements follows that Condition will be executed If it is false then checks the Condition3 and statements follows that condition will be executed if all the 3 Conditions occur false then Statements in the Else will be executed.

Let us see an example of finding day by inputing day number.

Module Example8
    Sub main()
        Dim DayNum As Integer
        Console.Write("Enter a Day Number1-7 :")
        DayNum = Console.ReadLine()
        If DayNum = 1 Then
            Console.WriteLine("Sunday")
        Else If DayNum = 2 Then
           Console.WriteLine(" Monday")
Else If DayNum = 3 Then
           Console.WriteLine(" Tuesday)
Else If DayNum = 4 Then
           Console.WriteLine(" Wednesday")
Else If DayNum = 5 Then
           Console.WriteLine(" Thursday")
Else If DayNum = 6 Then
           Console.WriteLine(" Friday")
Else If DayNum = 7Then
           Console.WriteLine(" Saturday")
Else
Console.WriteLine("Invalid Input")
        End If
    End Sub
 End Module



Wednesday 5 June 2013

If Else in VB.NET with Odd Even Checking Example


If else Control Structure in VB.NET with Odd Even Checking Examples



In this blog we another example program of  If Else control structure in VB.NET.

Module Example7
    Sub main()
        Dim Num As Integer
        Console.Write("Enter a Number: ")
        Num = Console.ReadLine()
        If Num Mod 2 = 0 Then
            Console.WriteLine(" Even Number")
        Else
           Console.WriteLine(" Odd Number")
        End If
    End Sub
 End Module

 


In the above program a new thing we saw Mod use of this operater is it returns remainder  in the division and all others are same as in the previous example program.  The above program checks whether the entered number is Odd number or Even number. Even number is a number which is divisible by 2 . Odd number is opposite of even number i.e  number not divisible by2.

Tuesday 4 June 2013

Checking Positive or Negative Number using VB.NET


Control Structure

In the previous blog we discussed if else control structure now we will some example programs.

Module Example6
    Sub main()
        Dim Num As Integer
        Console.Write("Enter a number greater than 0 or less than 0 : ")
        Num = Console.ReadLine

        If Num > 0 Then
            Console.WriteLine(" Positive Number ")
        Else
            Console.WriteLine(" Negative Number ")
        End If
        Console.ReadKey()


    End Sub
End Module

The above program check whether the given number is positive or negative. Positive number is one which is greater than 0. Negative number is one which is less than 0. Using above program we can find out given number is Positive or Negative.


 
check google pagerank

Monday 3 June 2013

Decision Making using VB.NET


Control Structure
Let us SEE control structure in VB.NET

Consider you go to fruit shop and ask for whether the shop sell apple or not just by asking the you get the answer similarly you are going to this in VB.NET.  First let us see an example .

Module Example5
    Sub main()
        Dim Asked As String = "apple"
        If Asked = "apple" Then
            Console.WriteLine("Apple Avalable!")
        Else
           Console.WriteLine("Not Avalable!")
        End If
        Console.ReadKey()
    End Sub
End Module

 
In the above example a string variable Asked is assigned with “apple” . One important thing I forgot to mention in the previous blog that string values are assigned with double quotes “ ” all other variables like Integer , Single (we have not seen yet ) are simple assign without quotes.

The statement
        If Asked = "apple" Then

Checks if  Asked variable value is “apple”  if it is statement in the if block is executed otherwise statement in the  Else block is executed.

Syntax of If Else Control  Structure
If condition then
Statements
Else
Statements
End If

We will see Examples in  If Else  Control Structure in the upcoming blogs.

Sunday 2 June 2013

String Data type in VB.NET



String Data type

In this blog we will the another datatype called 'String' this datatype stores texts .

Dim str as String =" Hello"

The variable str contains 'Hello' like this we can store any text in String datatype.

Let us see an example.

Module Example4
    Sub main()
        Dim Greet As String = "Hello, "
        Dim Msg As String
      
       Console.Write("Enter Your Name: ")
        Msg = Console.ReadLine()

        Console.WriteLine()
        Console.WriteLine(Greet & Msg)
        Console.ReadKey()
    End Sub
End Module




The above example have two variable Greet and Msg, Greet is assigned with the text " Hello" and Msg will get value during runtime output will display Hello with value containing in Msg variable.

In the next blog we will see Control Structure we mentioned in first blog.

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.