• 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 » Visual Basic

What steps are needed to assign property values to an object

By Dinesh Thakur

Inside our class, we define variables, which are the properties of the class. We could declare all the variables as Public so that all other project code could set and retrieve their values.

 

However, this approach violates the rules of encapsulation that require each object to in charge of its own data. Encapsulation is also called data hiding. To accomplish encapsulation, we will declare all variables in a class module as Private.

When our program creates object from our class, we will need to assign values to the properties. Because the properties are private variables, we will use special property procedures to pass the values to the class module and to return values from the class module.

 

 

What actions trigger the initialize and the terminate event of the object

By Dinesh Thakur

The Class_initialize event is triggered when an object is created and the Class_initialize event occurs when an object goes out of scope or is terminated with

 

Set ObjectName = Nothing. These event procedures are useful for doing any setup work for making sure that the memory allocated for an object is released.

 

Public Sub Class_Initialize()

‘ Create the collection object

Set mProducts = New Collection

End Sub

Public Sub Class_Terminate()

‘ Remove the collection from memory

Set mProducts = Nothing

End Sub

 

Explain the difference between ByVal and ByRef. When is each used

By Dinesh Thakur

When we pass a value to a procedure we may pass it ByVal or ByRef.

 

 

ByVal

 

ByRef

The ByVal sends a copy of the argument’s value to the procedure.

The ByRef sends a reference indicating where the value is stored in memory, allowing called procedure to actually change the argument’s original value.

When we want to pass copy of argument we can use ByVal keyword.

When we want to pass the reference to the calling procedure we can use ByRef keyword. The ByRef is Default.

Syntax is :

Private Sub Procedure_name(ByVal var as Integer)

Syntax is :

Private Sub Procedure_name(ByRef var as Integer)

For ex.

Private Sub SelectColor(ByVal lngIncomingColor as Long)

‘ Do Something

End Sub

For ex.

Private Sub SelectColor(ByRef lngIncomingColor as Integer)

‘ Do Something

End Sub

 

 

What are the purpose of a Declare Statement

By Dinesh Thakur

Declaring variables means naming the variable and specifying their data types, that is declaration statements establish our project’s variables and constants give them names, and specify the data type they will hold.

 

These declaration statements are not considered as executable ; that is, they are not executed in flow of instructions during program execution.

Although these are several ways of declaring the variables, the most commonly used way is the Dim statements with the data type. We can omit the data type, then default data type becomes variant.

 

Here are some sample examples for declaration statement :

 

Dim strName as String ‘Declared the String variable

Dim intCount as Integer ‘Declared an Integer variable

Dim curDiscount as Currency ‘Declared a currency variable.

 

How Arrays are declared and initialized in Visual Basic

By Dinesh Thakur

A standard structure for storing data in any programming language is an array. Whereas individual variables can hold single entities, such as a number, date, or string, arrays can hold sets of related data.

 

An array has a name, as does a variable, and the values stored in it can be accessed by an index.

 

Declaring Arrays : Single Dimensional Array—Used to store long sequences of one dimensional data. Unlike simple variables, arrays must be declared with the Dim statement followed by the name of the array and the maximum number of elements it can hold in parantheses,

e.g. Dim Sal(15)

Multidimensional Array—To store the data in a tabular or matrix form, we need two dimensional array and to store sequences of multidimensional data we need multidimensional array.

In two dimensional array, first index represent the row and the second represents the column.

e.g. Dim Board(5,5) As Integer

 

Dynamic Arrays : Sometimes you may not know how large to make an array. Instead of making it large enough to hold the maximum number of data, you can declare a dynamic array. The size of a dynamic array can vary during the course of the program.

To create a dynamic array, declare it as usual with the Dim statement, but don’t specify its dimensions :

 

Dim DynArray()

Later in the program, when you know how many elements you want to store in the array, use the ReDim statement to redimension the array, this time with its actual size.

 

ReDim DynArr(UserCount)

Here UserCount is a user-entered value.

The ReDim statement can only appear in a procedure.

 

Multi-Dimesional Array

By Dinesh Thakur

 You may need to use two subscripts to identify tabular data, where data are arranged in rows and columns. To define a two-dimentional array or table, the Dim statement specfies the number of rows and columns in the array. The row is horizontal and the column is vertical.

 

Syntax:

Dim ArrayName ( [ LowerLimit To ] UpperLimit, [ LowerLimit To ] UpperLimit ) As Datatype

Example:

Dim strName ( 2, 3 ) As String

Dim strName ( 0 To 2 , 0 To 3 ) As string

Why would a list box control need both a ListBox property and an ItemData property

By Dinesh Thakur

List Index property is used to determine the array subscript. List Index property holds the position or index of the selected item in the list. We could then use this index with one minor change to access the group total. List index property always begins with 0.

 

VB offers another handy property for list boxes and combo boxes that can be a big help when working with indexes. The ItemData property can associate a specific number with each item in the list. Each element of the list property can have corresponding Item Data that does not change the list is sorted.

 

Name some situation in which it is important to perform validation when working with subscripted variables

By Dinesh Thakur

Sometimes, array are referred to as tables or subscripted variables, all referenced by the same name. When we use a control array, the individual controls are referenced as optCoffee(0) or optCoffee(1). The same notation is used with variable arrays. Therefore, in an array for storing names we may have strName(0), strName(1), strName(2) and so on.

Describe the logic of a table lookup

By Dinesh Thakur

Consider the eight scout troops and their ticket sales. Now the groups are not numbered 1 to 8, but 101,103,110,115,121,123,130 and 145.

The group number and the number of tickets sold are still input, and the number of tickets must be added to the correct total. But now we must do one more step – determine to which array element to add the ticket sales, using a table lookup.

 

The first step in the project is to establish a user-defined type with the group numbers and totals and the dimension an array of the new type. Before, any processing is done, load the group numbers into the table.

 

Place the following statements in the general declaration section of a form module:

 

Private Type GroupInfo

intNumber as Integer

intTotal as Integer

End Type

 

Dim mudtGroup(1 to 8) as GroupInfo

 

Then initialize the values of the array element by placing these statements into the form_load procedure:

mudtGroup(1).intNumber = 101

mudtGroup(1).intNumber = 103

mudtGroup(1).intNumber = 110

etc.

 

During the program execution the user still enters the group number and the number of tickets sold into textboxes. The technique used to find the subscript is called a table lookup.

 

 

Define the following terms

By Dinesh Thakur

a) Arrays:

A variable array can contain a list of values, similar to list box or combo box. VB actually stores the list property of a list box or a combo box in an array.

 

b) Element:

Each individual variable is called an element of the array. The individual elements are treated the same as any other variable and may be used in any statement, such as an assignment or a Printer.Print.

c) Subscript:

The subscript which may also be called an index inside the parenthesis is the position of the element within an array. Subscripts may be constants, variables, or numeric expressions. Although the subscripts must be integers, VB will round any non integer subscript.

d) Control array:

A control array is a group of controls that all have the same name. All controls in an array must be the same class. An advantage, of using control array, rather than independent controls, is that the controls share one Click event.

e) Subscripted Variables:

The subscript which may also be called an index inside the parenthesis is the position of the element within an array. Subscripts may be constants, variables, or numeric expressions. Although the subscripts must be integers, VB will round any non integer subscript. The real advantage of using an array is not realized until we use variable for subscripts in place of the constants.

strName(intIndex) = “”

Printer.Print strName(intIndex)

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)

What does the phrase standard code module mean

By Dinesh Thakur

1. When using multiple forms in a project, it is important for you to consider each sub procedure or function procedure that you create. If the procedure will be used in only one form, then it should be included in the code for that form module.

 

If, in fact, you will need to use the procedure in multiple forms, write the procedure in standard code module.

 

2. A standard code module is a Visual Basic file with extension .bas, which is added to project. Standard code module do not contain a form, only code .

 

3. Create a new standard code module by selecting the Add Module command on the project menu. Select module on the new tab of the add module dialog box and click open. A new code window titled module1 opens on the screen. Module is also added to project explorer.

 

4. Standard code module has a general declarations section and procedure, just like form module. You can declare a variable and procedure as you declare in form module.

 

difference between declaring a variable in the General Declaration section of a standard code module and declaring variable in the general declaration section of a form code module?

By Dinesh Thakur

The variables declared in the General declaration of the section of standard code module are global and can be accessed from any other module, if the variable is public.

 

The variables declared in the General declaration of the section of the form module are not global those can not be accessed from any where in the project.

The variables declared static in the standard code module are static while project is running.

 

List some of the items generally found in an About Box

By Dinesh Thakur

One type of additional form in a project is an About box, such as the one you find in most Windows programs in help menu.

 

Usually an about box gives you the name and version of the project as well as information about programmers or company.

About box typically holds labels and OK command button, and perhaps images, logs or shapes

 

What is a Purpose of Splash Screen

By Dinesh Thakur

Perhaps you have noticed the logo or window that often appears while program is loading. This initial form is called splash screen.

Professional applications use splash screens to tell the user that the program is loading and starting.

 

It can make a large application appear to load and run faster, since something appears on the screen while the rest of the application loads.

You can create your own splash screen or use the splash screen template included woth Visual Basic. In the add form dialog box, choose the Splash screen to add a new form; then modify the form as you need.

 

 

What is the Term Used for the First Form to Display in the Project

By Dinesh Thakur

The term used for the first form to display in the project is called start up object; this start up object might be a form or Main procedure.

 

When you begin execution with a Main Sub procedure, you must explicitly load and show each form. Usually splash screen is displayed as modeless so that the Load statement the project’s Main form is loaded, but not shown. The last actions performed by the screen form is to unload the splash screen and show the Main Form.

 

 

Different Startup Form After the Project has been Created

By Dinesh Thakur

The startup form is the first form created in a project. However, you can select a different form to be the startup form, or you can specify your own Main Procedure.

 

You after creating a project you can set the startup form by following steps given below:

 

Step1: Select Project Properties form the Project Menu of the project name in the project explorer window and choose Project Porperties.

 

Step 2: In the Project Properties dialog box, click on the general tab.

 

Step 3: Drop down the list for Startup Object and select Sub Main. The Main Sub procedure displays frmSplash and loads required form.

 

Step 4: Click on OK.

 

 

Explain how to include an Existing Form in a New Project

By Dinesh Thakur

Forms may be used in more than one project. You might want to use a form that you created for one project in a new project.

 

Each form is separate module, which is saved as separate file with an .frm extension. All information for the form resides in a file, which includes the code procedures and visual interface as well as property settings for controls.

To ad as existing form to a project, use the add Form command on the project menu and select Existing tab. You need to specify the location and name of the form where it can found.

Steps for adding a existing form:

Step 1: Select Add Form from the Project menu.

Step 2: In the Add Form dialog box, select the Existing Tab and locate the folder and select file desired.

Step 3: Click on Ok

This will add that for to your project and it will appear in the project explorer.

 

 

« Previous Page
Next Page »

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