Table of Contents hide
Example : A VB .Net Looping Statement Examples or Program to display all the numbers from 10 to 20 using For Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()

        Dim i As Integer

        For i = 10 To 20
            Console.Write(" ")
            Console.Write(i)
        Next
        'Next i
        Console.ReadKey()

    End Sub
End Module

Output:
10 11 12 13 14 15 16 17 18 19 20

------------------  OR  ------------------

Module Module2
    Sub Main()

        Dim i As Integer

        For i = 10 To 20 Step 1
            Console.Write(" ")
            Console.Write(i)
        Next        
        Console.ReadKey()

    End Sub
End Module

Output:
10 11 12 13 14 15 16 17 18 19 20


NB: 
(A)When run the program and found error with this message "Error 1'Sub Main' was not found in 'ConsoleApplication1.Module1'.	ConsoleApplication1" then double click on this message and select the option appeared in prompt dialog box and then ok. Error will removed and program working.

(B) We can also use  Next i in place of Next in the above program.
Example : A VB .Net Looping Statement Examples or Program to display all the numbers from 20 to 10 using For Loop through Module via Console Application.
Module Module2
    Sub Main()

        Dim i As Integer
        For i = 20 To 10 Step -1
            Console.Write(" ")
            Console.Write(i)
        Next
        Console.ReadKey()
    End Sub
End Module

Output: 
20 19 18 17 16 15 14 13 12 11 10
Example : A VB .Net Program to display all the numbers from 10 to 20 with the interval/gap of 3 using For Loop through Module via Console Application.
 Module Module2
    Sub Main()

        Dim i As Integer
        For i = 10 To 20 Step 3
            Console.Write(" ")
            Console.Write(i)
        Next i
        Console.ReadKey()
    End Sub
End Module

Output:
10 13 16 19
Example : A VB .Net Looping Statement Examples or Program to display all the numbers from 20 to 10 with the interval/gap of 3 using For Loop through Module via Console Application.
Module Module2
    Sub Main()
        Dim i As Integer
        For i = 20 To 10 Step -3
            Console.Write(" ")
            Console.Write(i)
        Next i
        Console.ReadKey()
    End Sub
End Module

Outlput:
20 17 14 11
Example : A VB .Net Program to display all the values of a table provided by the user at run time/dynamically using For Loop through Module via Console Application.
Module Module2
    Sub Main()
        Dim i, num As Integer

        Console.WriteLine("Enter any number to print the table")
        num = Console.ReadLine()

        Console.WriteLine("Table of " & num)
        For i = 1 To 10
            Console.WriteLine(num & " * " & i & " = " & i * num)
        Next
        Console.ReadKey()
    End Sub
End Module

Output:
Enter any number to print the table
5
Table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
Example : A VB .Net Program to display all the values of an array provided by the programmer statically using For Each Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim arr() As Integer = {1, 2, 3, 4, 5}
        Dim i As Integer

        For Each i In arr
            Console.WriteLine("Value of index {0} is {1}", i - 1, i)
        Next

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadLine()
    End Sub
End Module

Output :

Value of index 0 is 1
Value of index 1 is 2
Value of index 2 is 3
Value of index 3 is 4
Value of index 4 is 5
Press any key to exit from output...

------------------  OR  ------------------

Imports System
Module Module2
    Sub Main()
        Dim str() As String
        str = {"Apple", "Orange", "Mango", "PineApple", "Grapes", "Banana"}

        Console.WriteLine("Fruit names stored in array are systematically :")

        For Each fruit As String In str
            Console.WriteLine(fruit)
        Next

        Console.WriteLine("Press any key to exit...")
        Console.ReadKey()
    End Sub
End Module

Output :
Fruit names stored in array are systematically :
Apple
Orange
Mango
PineApple
Grapes
Banana
Press any key to exit...
Example : A VB .Net Program to display all the values from 1 to 10 using While Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim x As Integer

        x = 1
        While x <= 10
            Console.WriteLine(x)
            x = x + 1
        End While

        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadKey()
    End Sub
End Module

Output :
1
2
3
4
5
6
7
8
9
10
Press any key to exit from output screen...

NB : At recent time, While-End While is used in place of While-Wend which is now old one and was used in VB6 or earlier.
Example : A VB .Net Program to display all the values from 1 to 10 using Do-While Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do
            Console.WriteLine(i)
            i = i + 1
        Loop While i <= 10

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

------------------  OR  ------------------

Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do While i <= 10
            Console.WriteLine(i)
            i = i + 1
        Loop

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

Output :
1
2
3
4
5
6
7
8
9
10
Press any key to exit from output...
Example : A VB .Net Looping Statement Examples or Program to Stop or Continue the program taking user confirmation DoUntil Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim Str As String
        Do Until UCase(Str) = "YES"
            System.Console.WriteLine("Do you want to stop the program?,Yes/No")
            Str = System.Console.ReadLine()
        Loop
    End Sub
End Module
Example : A VB .Net Program to display all the values from 1 to 10 using Do-Until Loop through Module via Console Application.
Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do
            Console.WriteLine(i)
            i = i + 1
        Loop Until i = 10

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

------------------  OR  ------------------

Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do Until i = 10
            Console.WriteLine(i)
            i = i + 1
        Loop

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

Output:
1
2
3
4
5
6
7
8
9
Press any key to exit from output...

------------------  OR  ------------------

Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do
            Console.WriteLine(i)
            i = i + 1
        Loop Until i < 10

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

Output:
1
Press any key to exit from output...

------------------  OR  ------------------

Imports System
Module Module2
    Sub Main()
        Dim i As Integer = 1
        Do
            Console.WriteLine(i)
            i = i + 1
        Loop Until i < 10

        Console.WriteLine("Press any key to exit from output...")
        Console.ReadKey()
    End Sub
End Module

Output:
1
Press any key to exit from output...
Example : A VB .Net Program to display the stored inputs using With – End With Statement through Class via Form Application.
Public Class Form1
    Public Property Tname As String
    Public Property Class_Name As Integer
    Public Property Salary As Single
    Public Property CourseTaught As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Shared Sub Main()
        'Create an Teacher object
        Dim Teacher As New Form1

        'To define the member of Teacher object  
        With Teacher
            .Tname = "Mr. Perfact"
            .Class_Name = 12
            .Salary = 53000.5
            .CourseTaught = "Computer Science"
        End With

        With Teacher
            'use Teacher as a reference  
            Console.WriteLine("Name of Teacher is : {0}", .Tname)
            Console.WriteLine("Class is : {0}", .Class_Name)
            Console.WriteLine("Salary is : {0}", .Salary)
            Console.WriteLine("Employee Email is : {0}", .CourseTaught)
        End With

        Console.WriteLine()
        Console.WriteLine("Press any key to exit from output screen...")
        Console.ReadKey()
    End Sub

End Class

Output:(Appears after few seconds)
Name of Teacher is : Mr. Perfact
Class is : 12
Salary is : 53000.5
Employee Email is : Computer Science

Press any key to exit from output screen...

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.