You are on page 1of 5

Visual Basic programming

A program is a set of instructions that guide the computer in carrying out a specific task. To write a program you need to have a programming language (software) such as: Visual Basic, Turing, Basic, Java, Fortran, Cobol, C++, etc. These are English-like languages that humans can read, understand and write, however the computer can not understand these languages! In order for the computer to carry out the instructions, the program must be translated to a language the machine understands, called machine language and then executed. The programs we write in Visual Basic are first translated by the VB software. When the statements in the original or source program are translated to machine language, called the object program, the program is said to be compiled and ready for execution

Steps To Creating a Program:


Software refers to a collection of instructions, called a program (VB calls them a solution) that directs the hardware (monitor, keyboard, mouse, CPU etc.) The first step in writing instructions to carry out a task is to determine what the output should be. The second step is to identify the data, or input, necessary to obtain the output. The last step is to determine how to process the input to obtain the output. Therefore, the problem solving process used will always consist of three steps: 1. input 2. processing 3. output When solving a computer problem, each assignment asks you to first create an IPO chart. IPO stands for input, processing and output.

Visual Basic Programming Environment (IDE - Integrated Development Environment)

Controls/Objects In VB, a program is started by drawing the user interface (the part of the program a user will see) on a form (the rectangular area with the grid marks in the center of the IDE). All the controls you can place on a form are in the toolbox, on the left side of the IDE. Controls you place on a form and the form itself are called objects. Examples of objects: form - a windows screen button label - user can not change during run time textBox - user can change during run time horizontal scroll bar pictureBox The Toolbox contains the following standard controls: Picture Box Label TextBox Button
2

GroupBox Check Box RadioButton ComboBox ListBox Horizontal Scroll Bar Vertical Scroll Bar Timer When placing several objects on a form, use the commands on the Format menu to place, size, and align the objects. First, drag the mouse around the objects to select them. Using the commands on the Format menu, you can then align or size the objects as necessary. Object properties can generally be set at either design time or run time Here is a form with Label, TextBox and Button objects.

Label Control
A label is a graphical control used to display text. The user cannot edit the text in a label. The most common use for a Label control is to identify controls that do not have a Caption property, such as the TextBox control. You can also use the Label control to display text such as status messages and other program information.

TextBox Control
You use a TextBox control to obtain information from the user or to display information provided by the application. Unlike information displayed in a label, the user can change information displayed in a text box. TextBox objects have a 'ReadOnly' property, that when set to 'true' does not allow the user to type into the textbox.
3

Button Control:
A Button performs a task when the user clicks the button. You use a Button control to begin, interrupt, or end a process. When clicked, a command button appears to be pushed in and so is sometimes called a push button. The most common event for a Button control is the Click event.

Object Naming Conventions


All objects you place on a form must be given a name, in this course. An object's name is used to refer to the object in your program code. You can assign any name to an object, but it is a good idea to adopt a naming convention and use it consistently throughout your programs.

Properties
Properties define the appearance and behavior of objects. Text, Font, and Name are common examples of properties. Properties are the attributes you set or retrieve. Each object has a long list of properties. These properties are very important to making the screen look right and to making the program act right.

Setting Properties at Design-Time:


Design-time is the time when you are laying out your form and writing your program code. Most properties of any object may be set at design-time. When an object on the form is selected, the properties for the object are displayed on the right-side of the IDE. To change or set a property, simply type your desired change in the area next to the property name.

Changing Object Properties during Run-Time


When the user is running the program, this is called run-time. Any property of any object can be changed during run-time. The general form of commands to change object properties is: objectname.property=value

Methods
Methods are actions that an object is pre-programmed to perform, such as move, hide, show itself, etc. The Hide method, is an example of a method that does not have arguments. The following code makes the form frmGame disappear from view: e.g. frmGame.Hide In contrast, the FindString method, which finds a string in a ListBox requires the desired string to be found. The following code returns the location in the ListBox of the word 'school':
4

e.g. location = lstBuildings.FindString("school")

Events
Events are actions the user can perfom, which objects can be programmed to respond to, such as click, double-click, keypress etc. An event is an action recognized by an object. Clicking a mouse or pressing a key are examples of events. Some events include: Activate Change DragOver GotFocus Load LostFocus

Each object has its own set of events that it recognizes. The events listed do not apply to all objects. For example, a form can recognize either a Click or DblClick event while a button only recognizes a Click event.

References
http://www.doyle.wcdsb.ca/ics3mi/notes.html ask.com/visualbasicprogram

You might also like