• 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 » Lists Loops and Printing

How do you control the horizontal spacing of printer output

By Dinesh Thakur

A function that controls horizontal spacing on the line is the spc(space). The space function differs from the tab function. In that we specify the number of spaces on the line that we want to advance from the last item printed.

 

Syntax is as follows :

Spc(number of characters)

Ex.

 

Printer.print Tab(20); “Name”; spc(5); “Phone”; Spc(5); “Address”

 

How do the Left , Right and len function operate

By Dinesh Thakur

VB provides string functions such as Left ,Right ,len.

 

Syntax is as follows:

 

Left(String Expression, no. of characters)

Right(String Expression, no. of characters)

 

String expression in Left and Right statements may be a string variable, string literal or text properties. Number of characters and start position are both numeric and may be variables, literals or numeric expressions.

 

Ex. Left(txtName.text,5)

„Returns first 5 characters

Right(strName,1)

„Returns last one character

Len(String Expression)

 

We can use the len function to determine the length of string expression. We may need to know how many characters the user has entered or how long list element is. The value returned by the len function is an integer count of the number of characters in the string.

Ex. Len(“Visual Basic”)

„Returns no. of character as 12

Len(txtName.text)

„Returns no. of character in the textbox

If len(txtNames.text)=0 then

Msgbox “Enter a Name”,VBInformation,”DataMissing”

End IF

 

Purpose of Printer.Print

By Dinesh Thakur

So far, any printed output has been done with the PrintForm method. When we print using PrintForm , all output is produced as a graphic, which does not produce attractive text.

 

In addition to printing forms, we will need to create reports or print small bits of information on the printer. We can use VB?s Print method to print text on a form, on the Printer object, or in the Debug window.

We can set up an output for the printer using Printer.print (object.method). Visual Basic establishes a printer object in memory for our output. Each time we issue a Printer.Print method, our output is added to the printer object.

 

Discuss how and when the values of the loop index change throughout the processing of the loop

By Dinesh Thakur

When the loop is executing we specify the increment number by which the value should be increase. Loop checks the condition whether it is true or not , if it is true then the body of the loop get executed and the variables value gets incremented by the specified number. Again, the loop checks the incremented value with the condition, if it is true then the body will execute and again increment value by the next value. But if the condition is false then it will exit the loop.

 

 

What are the steps in processing a FOR-NEXT Loop

By Dinesh Thakur

Do-Loop construct is used when we do not know how many iterations will be performed , where as when we know exact number of execution on the block of code, For-Next construct is used. To use this construct we have to use a counter.

 

We will always loop from some starting value to some end value. By default a For-Next loop always increment by one every time through the loop. The format of the For-Next statement is as follows :

 

For intCounter = intStart to intend

[Step in Increment]

Next[intCounter]

 

To do first iterations intCounter is initialized to intStart value. When execution reaches to next statement it will increment the value of counter by one & control will again go to the fist statement. If the value of intStart is less than intend, second iteration will occur and so on. This is how the for-loop will execute. By Default if we do not write step , it will increment intCounter by one. If we want to increment value of intCounter while value of step other than one then we have to write step statement with which we will tell VB to increment value with specified number of steps for each interations.

 

Ex. For intCounter = 1 to 5

Form1.Print intCounter

Next

Ex. For intCounter = 0 to 10

Step 2

Form1.print intCounter

Next

 

Explain differences between Do/Loop and For-Next Loop.

By Dinesh Thakur

 

 

Do/Loop

 

For-Next Loop

Do-Loop construct is used when we don?t know how many iterations will be performed.

When we know the exact number of execution on the block of code, For-Next construct is used.

Do-while tests the loop condition each time through the loop & it keeps executing while the test expression is a true value

To use this construct we have to use a counter. We will always loop from star value to some end value.

In this we will have to specify the increment number.

In For-Next loop always increment by one by default

General Syntax is :

Do while <condition>

<statements>

Loop

General Syntax is :

For intCounter = intStart to intend

[step to increment]

<statements>

Next [intCounter]

Ex. Dim intNum as integer

Do While intNum < 100

lblNumber.Caption=intNum

intNum = intNum + 1

Ex.

For intCount = 1 to 5

Form1. Print intCount

Next

 

Explain difference between a pretest and a posttest in a Do/Loop.

By Dinesh Thakur


 

PreTest Do/Loop

 

PostTest Do/Loop

 

1. Do-while tests the loop condition each time through the loop & it keeps executing while the test expression is a true value.

 

Loop while we check the condition at the bottom.

 

2.When the conditional expression is false then

 

When the loop while is used ,the body of loop

the statements in Do/Loop are skipped.

is executed at least once, since the condition is at the bottom of the loop.

 

3. General Syntax is :

Do while <condition>

<statements>

Loop General Syntax is

General Syntax is :

Do

<statements>

Loop while<condition>

 

4. Ex.

Do While intNumber < 100

lblNumber.Caption=intNumber

intNumber = intNumber + 1

Loop

Ex. Dim intNum as integer

Do

Form1.print intNum

intNum = intNum +1

Loop while(intnum <= 10)

 

In what situation would a loop be used in a procedure

By Dinesh Thakur

A loop is series of one or more statements that executes more than one time. Loop statement repeats until a certain predefined condition is true. Two types of loop structures are available in VB. The do loop and for-next loop. The do loop constructs offers many variations and is used typically. If we do not know how many iterations will be performed.

When and how the information is placed inside the listbox or combobox

By Dinesh Thakur

We can use several methods to fill a listbox & combobox. If we know the list contents at design time and list never changes , we define list item in properties window.The list property holds the list of items for a listbox or combobox. To define the List property at design time, select the control and scroll the properties window to the List property.

 

Click on the down arrow to drop down the empty list and type our first item. Then press Ctrl + Enter to move to the next list item. Continue typing items and pressing Ctrl + Enter until we r finishe. On the last list item , do not press Ctrl + Enter or we will have an extra (blank item) on the list.

 

For adding items to the list during program execution , we will use the AddItem method in an event procedure. Syntax is as follows :

Object.addItem value (index)

Ex. lstSubject.addItem “VB”

lstSubject.addItem txtSubject.text

 

Explain the purpose of ListCount and ListIndex Property

By Dinesh Thakur

ListCount :

 

The application uses the list count property of listbox to store the number of item in the list. ListCount is always one more than the highest list index, since list index begins with zero.

 

Ex. totalItem = lstItem.listCount

ListIndex :

 

When a project is running and the user selects an item from the list, the index number of that item is stored in the listIndex property of the listbox. The listindex of the first item in the list is zero. If no list item is selected , the list index property set to -1. We can use listIndex property to select an item in list or deselect all items in code.

 

Ex. lstCopyType.listIndex = 3

lstCopyType.listIndex = -1

„Deselect all items in list.

 

How can we make scroll bars appear on a listbox or combobox

By Dinesh Thakur

After adding items in list property of the combobox or listbox we may have to resize it .

 

When the size of the listbox or combobox is small and it contains many list items then VB automatically shows scrollbar on listbox or combobx to scroll down from top-bottom.

Describe the Three Styles of ComboBox

By Dinesh Thakur

Combobox:

 

A combobox control is combination of textbox and listbox. This control enables user to select either by typing in the text into combobox or by selecting items from the list.

 

The combobox controls has three different style that can be set .

 

a) Drop down combo (style 0)

b) Simple combo (style 1)

c) Drop down list (style 2)

 

a)Drop down combo :

 

It first appears as only an editable area with down arrow button to drop down list portion with this style. We can either type text into text portion which is an editable area or select a value from drop down list. The list portion status hidden until the user clicks down arrow button to drop down list portion.

 

b)Simple combo:

 

This style looks like listbox setting directory underneath a textbox. The listbox , which below textbox which is always visible showing an item present in it. Scrollbar

display decides the list if there are to many item to display in listbox area. So important thing is , list is always present below textbox. Hence there no downward arrow button which are used to open a list, in case of drop down combo.

 

c)Drop down list Combo:

 

The drop down list combobox terms combobox into drop down listbox at run time , the control looks like drop down combobox. The user click on down arrow view list. Main difference between drop down combo & drop down list combo are editable are in the drop down list disable i.e. means user can only select from item listed in portion of listbox of the combobox and he can?t type and item in the next or edit area of the combobox.

 

ListBox and ComboBox

By Dinesh Thakur

ListBox :

ListBox present a list of choices that are displayed vertically in single column, if number of items exist the value can be displayed scrollbar automatically appear on control.

ListBox have list property contain list or item to display. To add the item at design time, click on list property & add item, press ctrl + enter after adding each item. To add item at runtime to AddItem method is used. Syntax is as following : 

object.AddItem item, index

The item argument string that represents text to add to the list . The index argument is an integer than indicated when in list to add the new item.

ComboBox :

A combobox control is combination of textbox and listbox. This control enables user to select either by typing in the text into combobox or by selecting items from the list.

 

The combobox controls has three different style that can be set .

a) Drop down combo (style 0)

b) Simple combo (style 1)

c) Drop down list (style 2)

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