Contact on: info@huryy.com Whatsapp: +254 716 362 016

 

BridgeCommercialDesignDesignsPeopleTech

COMPUTER PROGRAMMING

12 Mins read

A Computer program is an application used to accomplish any task imaginable in soft form.

Basic steps in programming

It is important to take a structured approach when programming thus implementing a program problem in certain order of steps.

  1. Plan the program’s tasks
  2. Design the user interface
  3. Write the program’s code
  4. Test and debug the program (using if possible alpha and beta testing methods)
  5. Document and distribute the program.

Type of common programs

  • Packaged programs they can be purchased from software stores, ordered via email and direct from manufacturer.
    • Costumed programs they are designed for a particular or specific purpose within a given organization.

STARTING VISUAL BASIC

Create anew project, which is a set of files that store information about the components of an application program.

  1. Start visual basic
  2. Choose file, new project (if new project dialog box does not occur)
  3. Select or specify the type of project you want to create e.g. Standard. exe option
  4. Then click okay and you will be placed in visual basic’s design environment

If the title bar is specified as design, it means that you are in design mode (design time) and you can design and code the program application.

When the program is running and the title bar is named as run mode; this means that the program is running or executing.

Visual basic applications are comprised of one or more components such as

  • Forms
  • Coded modules
  • Classes
  • Controls
  • Other components

Visual basic has the Project explorer, which consists of a list of the contents of the current project. It grows as many components are added.

RUNNING PROGRAM

 To run the program you need to execute visual basic start command using any of the methods

  • Click the start button on visual basic toolbar
  • Choose run, start
  • Press F5

Forms

A Form is a container that holds all the other controls such as labels, textboxes, pictures and access databases and make up part of the user interface.

Forms have features found on a window in a program. It contains a title bar, a control menu, and asset of minimize/maximize/restore, and close buttons.

Design time features are:

Close buttons 

  • They are always present even if the properties are set in such away that they are not visible at runtime.

Design grid

  • It is a grid of dots that allows you to line up controls easily, as you are designing your interface.

The form oversees the use of objects that make up the interface, including storing program codes that relates to the objects on the form and respond to events.

Some form properties

Property Name Description
border style Sets the type of border that is used for the form
Control box Determines whether the controlbox(containing the move and close menus) is visible when the program is running.
font Determines the font used to display text on the form
icon Determines the icon that is shown in the form’s title bar and that appears when the form is minimized.
Maxbutton Determines whether the maximize button is displayed on the form when the program is running
Mdichild Determines whether the form is a child form for an MDI application
minbutton Determines whether the minimize button is displayed on the form when the program is running.
startup position Determines the initial position of a form when it is first shown.
window state Determines whether the form is shown maximized, minimized, or in its normal state.

Controls

Visual basic controls let you perform a wide variety of tasks including editing text, displaying pictures, and interfacing with a database. The liberal use of controls has always been one of VB strongest features.

Controls are objects that perform specific tasks and have associated properties, events and methods.

E.g. using a text box control, you can set properties to determine the size of the text box, the text that it displays and the color of the text and background.

You are not limited to using only the control s provided by Microsoft, the design allows easy integration of third-party controls which increases chances of finding a control to perform almost any task you want, from data acquisition to custom reporting to specialized graphics processing to game play, and everything in between. You can create your own activex control for use in your programs.

N/B

              A control is a miniature program in itself that perform certain tasks for you e.g. a textbox contain internal code that allows it to process keystrokes so that it knows, characters when you press back space key.

Control properties

          They are adjectives that describe one specific thing about an object and modify objects appearance when you run your program. Hence a windows appearance is defined by a set of properties thus they are settings that control the appearance and behaviour of an object. All objects do not have it set of properties although we have common properties found in many objects.

Common properties

Name, Index, Left, Top, Height, Width, Enabled, Visible, Caption

Left and Top

  • Describe the position of the form on the screen

Width and height

  • Define the size of the form on the screen

Caption

  • Dictates what is shown in an object title bar

Name

  • Describes a unique identifier by which you can refer to the object in code.{name property is very important , in that it identifies the control since the program may have many controls of the same  type and you can also use the control name  property to indicate the procedure in which a particular code statements written.}

Visible

  • Determines whether an object can be seen on the screen by setting it true (to be viewed) and false otherwise.

Enabled

  • Determines whether the users can interact with an object setting it either to true or false.

Control methods

Is a program function that is built into the object. As properties, they are referenced using code via the dot notation

E.g. form1.printform-prints an exact image of the form named form1on the line printer

Although different objects have different methods, many objects have the same  or common methods.

Like

Drag

  • This handles the operation of the users’ dragging and dropping the object within its container.

Move

  • Changes the position of an object

Set focus

  • Gives focus to the specified control

Zorder

  • Determines whether an object appears in front of or behind other objects in its container.

Controls responding to action with events

Objects respond to actions, whether generated by the users or externally. Response to actions are handled through use of events .generally an object is the set of events it can raise and the user actions that trigger them.

Intrinsic Controls

CONTROL DESCRIPTION
picture box Displays graphics .Can also serve a container for other controls.
Label Displays text that the user
Text box Displays text . also allows the user to enter and edit the text.
Frame Serves as a container for other controls. Provides grouping of controls
Command button Allows the user to initiate actions by the button.
Check box Lets the user make the a true /false choice
Option button Lets the user choose one option from a group of items.
Box Lets the user choose form a list of items or enter anew value.
List box Lets the user choose from a list of items.
Horizontal scrollbar Lets the user choose a scrollbar value based on the position of the button in the bar.
Vertical scrollbar Serves as a horizontal scrollbar.
Timer Lets the program perform functions on timed basis.
Drive list box Lets the user select disk drive
Directory list Lets the user select a box directory or folder
File list box Lets the user select a file
Shape Displays a shape in time form
Line Displays a line on the form
Image Similar to a picture box control. uses fewer system resources but doesn’t support as many properties, events and methods..
Data control Provides an interface between the program and a data source
   
Ole Provides a connection between the program and an OLE server.
Common dialog Allows user of windows standard dialog boxes to retrieve information such as file names, fonts and colors.
Label control It does not allow the user to enter text directly; it contains events and properties that allow the programmer to manipulate the text directly from code. E.g. label caption=”time is”
Textbox It has property that makes programs and user interaction versatile. Multiline and scrollbar properties in the textbox windows. They are useful for handling large amounts of text. Scrollbar property has affect on the textbox only if its multiline property is set to true

Controls for displaying text

Textbox and label

Textbox

Allow both data/text display and also allow text input. A text box control must be adding to a form so that it can be used.

The textbox control is found in the tool box as one of the default controls on toolbox

Steps followed to use a text box

  1. Click the tool for the textbox control in the toolbox. (To know if it is a text box let your mouse pointer pause over each control in turn to see atooltip.)
  2. Move the mouse pointer to the form .Note that the pointer will change into across hair, indicating that you’re about to draw the control.
  3. Move the pointer to one corner of the area where you want to draw the control.
  4. Click and hold the left mouse button
  5. Drag the mouse to where you want diagonally opposite the corner of the control.

Label

 Are designed only to display text. They inform users what type of information is to be entered in the textboxes if laced next to input field. It has events and properties that allow the programmer to manipulate the text directly from code. If you want to display more text, pay attention to the auto size and word wrap properties. If auto size is true the size of the label control automatically adjusts to fit the text being displayed, otherwise label remains same size.

If word wrap is false the label expands horizontally to a low the caption to fit, even if the label grows so large that it passes the right edge of the screen. If the word wrap is true the label expands vertically to allow enough times of text to accommodate the caption even if the label runs off the bottom edge of the screen.

Steps followed to use a label

  1. Select the label control’s tool in the tool box
  2. Draw a label control to the left of the first text box control
  3. In the properties window change the label control’s name property to start with lbl e.g. lblbookid
  4. Change the label control’s caption property to <name>
    1. lblbookid.caption=<name>
  1. change the label’s alignment property to suit your application

                            e.g. lblbookid.alignment = 0-leftjustify

                                                                       1-rightjustify

                                                                       2-center

The command button

This control lets users initiate actions by clicking the button. you can set up a command button control by

  • Drawing the button on the form
    • Then set the caption property to the text that you want displayed on the button’s face.
    • To activate the button, just place code in the button’s click event procedure.

To access commands through the keyboard

  You make use of access keys assigned using the ampersand sign “&” ,on the button caption.

To use the access key, the user holds down the alt key and processes the access key to trigger the command button controls’ a click event.

             e.g. command1.caption=&”print”

     It will appear as     Print and to use the command using the keyboard press alt + p

Checkboxes

when  a checkbox is on ,a check mark(Ö) is d displayed in the box.It indicates that the answer to the checkbox ‘s corresponding question  is “yes’ .when the  checkbox  is off  or unchecked the box is empty, indicates an answer  of “NO”

option buttons-they exist a group and only one of them can be selected at a time .They are useful for presenting  a fixed list of mutually exclusive choices.

      Two ways of using the option button.

1.) Use   the click event if you want to take an action when users select  an option. This is useful when using control array and code is typed in the option procedure.

2.) Do not write any code in the  optional button event .Instead use if statement  in a relevant  controls procedure e.g. button to  check if they are true .

 
The list box

-The key parts of the list box are the following

Item list

  • Which is the list of items from which the users can select.
    • They are added to the list  in the design environment or by our program as it is running  mostly using code

Select item

This item is chosen by the users. Depending on the style of list you choose a selected item indicated by a highlight bar or by a check in the box next to the item.

Scroll bar

This part indicates that more items are available on the list than will fit in the box and provides the users with an easy way to view the addition items. , But it does not have horizontal scrollbar although vertical scrollbar appear as default.

Filling list box using code

    Private sub form_load()

          Dim I as integer

          For  I=1 to 100

                 List1.AddItem   I

           Next I

To clear using clear method

                  List1.clear

To print items from the list you can use list property of the list box indexed from “ 0”

                Print list1.list (index)

Listcount-represent the number of items in alistbox

                List1.listcount

Listindex- represent  index of selected items.

                List1.ListIndex

Removeitem-remove item from the item list by specifying the array index of the item.this property works only for  asingle selection.

                             List1.RemoveItem   ListIndex

      Using index with additem method you can specify the location within the list where you want the new item to appear.

Setting the appearance of a list box

     This can be done by using or setting the style property to either:

                               0-standard

                               1-checkbox

     the values can be changed at runtime by setting its value to one of the  intrinsic constants

                          vblistboxstandard or vblistboxcheckbox        respectively

the otherway to change the list’s APPEARANCE  is to use the columns property that has a default value of zero

Setting it to 1

         Causes the list to be presented  with one column at atime,but to scroll horizontally instead of vertically.

Setting it to values greater than 1

         Causes the list to display in ,the number of columns specified by the property.

Working with multiple selections

Applicable  only when you need to select more than one element .this is done using multiselect property and it has three possible setting.

  1. 0-none

Is default setting showing that multiple selection is not required or permitted.

  • 1-simple

Users can click an item with the mouse to select it or click a selected item to deselect it. Using the keyboard, users can make use of the cursor keys to move the focus (dotted line border)to an item  and then presss the space bar to select or deselect it.

  • 2-extended

Is more complex, here users can use standard windows techniques to quickly select multiple items.you can select a range of items by clicking the first item in the range and then ,while holding down the shift key,click the last item in the range; all items in between the first and lat items are selected .to add or delete a single item to or from the selection,userts hold down       the control key while clicking the item.

Selected property is an array that has an element for each item in the list. The value of the selected property for each item is either true (if the item is selected) or false (when not selected). To display item selected you can print on the form

 e.g.

      numitem=list1.listcount

       For I=0 to numitem-1

             If list1.selected (I) then

                Form1.print list1.list (I)

             End if

        Next I

131 posts

About author
Web developer, Web-based Software systems designer, and developer, Networking, Social Marketer, PHP programmer, Photographer, blogger. Student final year project helper.
Articles
Related posts
Computer ScienceTechVideos

Login Page HTML, CSS Template.

2 Mins read
Login Page HTML, CSS Template.
Computer LessonsComputer ScienceTech

How to resolve “mcrypt extension is missing. Please check your PHP configuration” error in XAMPP Server?

1 Mins read
mcrypt extension
Tech

COMPUTER SOFTWARE.

1 Mins read
COMPUTER SOFTWARE. COMPUTER SOFTWARE refers to the various programs & data used in a computer system that enable it perform a no. of specific functions. Software instructs the computer on what to do and how…

23 Comments

Leave a Reply

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