• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » VB » Decisions and Conditions

Different Looping Constructs in VB

By Dinesh Thakur

Loop statements allow you to execute one or more lines of code repetitively. Visual Basic supports the following loop statements:

Do……Loop : The Do……Loop executes a block of statements for as long as a condition is True. Visual Basic evaluates an expression, and if it’s True, the statements are executed. If the expression is False, the program continues and the statement following the loop is executed.

 

There are two variations of the Do……Loop statement. A loop can be executed either while the condition is True or until the condition becomes True. These two variations use the keywords While and Until to specify how long the statements are executed. To execute a block of statements while a condition is true, use the following syntax :

 

Do While condition

statement block

Loop

 

To execute a block of statements until the condition becomes True, use the following syntax :

 

Do Until condition

statement block

Loop

 

Another variation of the Do loop executes the statements first and evaluates the condition after each execution. This Do…Loop has the following syntax :

 

Do

statements

Loop While condition

Or

Do

statements

Loop Until condition

 

For…..Next : The For…….Next loop is one of the oldest loop structures in programming languages. Unlike the Do….loop, the For …..Next loop requires that you know how many times the statements in the loop will be executed. The For…Next loop uses a variable(it’s called the loop’s counter) that increases or decreases in value during each repetition of the loop. The

 

For…..Next loop has the following syntax :

 

For counter=start to end[Step increment]

statements

Next[counter]

 

The keywords in the square brackets are optional. The arguments counter, start, end and increment are all numeric. The loop is executed as many times as required for the counter to reach the end value.

While ………Wend : The while……wend loop executes a block of statements while a condition is True. The while…..wend loop has the following syntax :

 

While condition

statement – block

Wend

 

If condition is true, all statements are executed and when the Wend statement is reached, control is returned to the While statement which evaluates condition again. If condition is still True, the process is repeated. If condition is False, the program resumes with the statement following the Wend statement.

 

Branching Statements in Visual Basic

By Dinesh Thakur

An application needs a built-in capability to test conditions and take a different course of action depending on the outcome of the test. Visual Basic provides three control flow, or decision, structures :

 

If……Then : The If….Then structure tests the condition specified, and if it’s True, executes the statement(s) that follow. The If structure can have a single-line or a multiple-line syntax.

 

The general form is : If condition Then statement

 

If……Then……Else : A variation of the If……Then statement is the If……Then……Else statement, which executes one block of statements if the condition is True and another if the condition is False. The syntax of the If… Then….Else statement is as follows:

 

If condition Then

statement block-1

Else

statement block-2

End If

 

Select Case : The Select Case structure compares one expression to different values. The advantage of the Select Case statement over multiple If…..Then…..Else statements is that it makes the code easier to read and maintain.

 

The Select Case structure tests a single expression, which is evaluated once at the top of the structure. The result of the test is then compared with several values, and if it matches one of them, the corresponding block of statements is executed.

 

The syntax is :

Select Case expression

Case value1

Statement block-1

Case value2

Statement block-2

.

.

.

Case Else

Statement block

End Select

 

difference between step into and step over

By Dinesh Thakur

Step into: Most likely you will use step into command more than you will use step over command.

When you choose step into, the next line of the code is executed and the program pauses again in break time. If line of code is call to another procedure will be displayed. To continue stepping through your program execution, continue choosing the step into command.

Step over: The step over also executes one line of code at a time. The difference between Step Over and Step Into occurs when your code calls to other procedure. Step over displays only one line of code in the current procedure.

 

Define the term Validation. When is it appropriate to do validation

By Dinesh Thakur

Validation is a form of self protecting; it is better to reject bad data then spend hours trying to find out an error only to discover that the problem was caused by a “user error”.

 

Checking to verify that appropriate values have been entered for the text box is called validation. The validation may include making sure that data is numeric, checking for specific values, checking a range of values, making sure that required data is entered.

What is a message box? Type Of message box

By Dinesh Thakur

A message box is special type of Visual Basic window in which you can display a message to the user. You can display message, an optional icon, a title bar caption, and command buttons in a message box.

 

You may want to display a message when the user has entered some invalid data or neglected to enter some required data value.

 

Message box constant:

 

vbQuestion : This constant sets a Question marked icon for the message box. It can be used as follows: MsgBox “Lets this be warning”, vbQuestion, “Error”

 

vbOkOnly: This constant makes message box to appear with only one ok button. Example: MsgBox “Welcome”, vbOkOnly “ Greeting”.

 

vbInformation: Shows information icon on the message box. Example: MsgBox “Welcome”, vbInformation “ Greeting”.

 

Primary Sidebar

Visual Basic Tutorial

Visual Basic Tutorial

  • VB - File Types Purpose
  • VB - Events
  • VB - Ole
  • VB - Controls Properties
  • VB - Project Steps
  • VB - Pretest Vs Posttest
  • VB - IDE
  • VB - Record Set
  • VB - Common Dialog Box
  • VB - Val Function
  • VB - Sub Vs Function Procedure
  • VB - Terms
  • VB - User Interface Elements
  • VB - Objects and Modules
  • VB - Variable’s Scope
  • VB - Message Box
  • VB - Data Vs Data-bound Control
  • VB - Branching Statements
  • VB - Do/Loop and For-Next Loop
  • VB - Grid Control
  • VB - Error Types
  • VB - Looping Constructs
  • VB - Relational Vs Logical Operator
  • VB - Control Purpose

Other Links

  • Visual Basic - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW