Monday, February 7, 2011

Visual Basic 6.0 - Session 1

•  Open VisualBasic 6.0
•  Use the file menu to open a new project with a blank form.
•  Use the properties window to set
  • Main.frm as the form name.
  • My programs as the caption.
  • BackColor to White.
  • BorderStyle to Fixed Single.
  • WindowState to Maximised.
•  Find the Menu icon and click on it to select it.  Enter the following menu headings:
    Quit
    Introduction
with indented subheadings of
            Example1
            Example2


    Click OK after each menu caption and name are typed.

•  Click on Quit menu heading and enter the following code.  This procedure is used to
exit from running the project display and return to the design screens.

   PrivateSub Quit_Click()
        Unloadme
        End
    EndSub

•  Use the <F5> function key to run the application to verify that the Menu structure is correct and that the Quit procedure is free from error.
•  Use the File menu to save your work as Main.frm and (your intitials)Project1.vbp
•  Use the file menu to open a new blank form (or the properties window)
•  Set the following form properties:
    form name as Welcome
    form name as Welcome
    caption to Example1
    BackColor to White
    BorderStyle to Fixed Single
    WindowState to Maximised
•  Click on the Example 1 main menu heading and enter the following code:

  PrivateSub Example1_Click()
      Welcome.Show
  EndSub

•  Save your work and run <F5> to ensure that it is free of errors. 
 •  Add two labels, an image and a command button to create a welcome screen. To do this
    Select label icon from the toolbox. Click towards the centre-top of your form and position and resize your label as required.
   With the label selected, use the properties window to Change the caption to WELCOME TO VISUAL BASIC
   Choose a bright back colour
   Set the font (Arial, underline, alignment centred, size 24 point, forecolour blue)
   Repeat to add the Enjoy label.
   Use the image icon on your toolbox to add the image to your form.  Use the properties window of the image to select a picture.
   Use the command Button icon to add the button.  Change its caption to RETURN.
   Then double-click the button and add the following line of code after the
   Command1_Click() procedure.
    –UnloadWelcome

•  Use the file menu to save your work and use <F5> to run the application.

•  DON’T FORGET TO SAVE (AND BACK UP TO FLOPPY) ALL YOUR WORK.

Event handlers and scroll bars
Some definitions to learn
•  An object is a thing — anything that appears on the screen.  An object has a set of properties.  Each property of the object has a value. e.g.   Label.Caption = “Welcome to Visual Basic”  where

                             Label is an object
                             Caption is a property of label
                            “Welcome to Visual Basic” is a value of the Caption property.

•  Events are things that happen on the screen.  Event handlers transfer data to procedures that complete the task.  The results of these procedures are returned back to other screen objects, e.g.  onChange   onClick


•  A procedure is a group of statements designed to perform a specific task.  A procedure attached to an object, such as a button, is a command used to make something happen, e.g.  

   PublicSub Command2_Click()
        Text1.Text=“Thisisaprocedure.”
   EndSub


Add new form to menu
As each new example and exercise solution is to be added to your project you will need to:
•  add a new form
•  set the form properties using the properties window
•  click on the main menu icon with the main form displayed to show the menu designer
•  add a new menu heading
•  click on the menu heading to show the procedure code
•  to the procedure code, add the statement
            FormXX.Show
    where FormXX is the new form name.

No comments:

Post a Comment