Search In Site

01 July, 2013

Organise your first project In Visual Basic


Organising your first project
The first step is to create a project template within VB, to organise and store your work. This will consist of a menu structure with headings that will let you access the many exercises and examples you complete.
Activity 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.
Private Sub Quit_Click()
Unload me
End
End Sub
·  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 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:
Private Sub Example1_Click()
Welcome.Show
End Sub
·  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.
– Unload Welcome
·  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.
Public Sub Command2_Click()
Text1.Text = “This is a procedure.”
End Sub

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.
Activity 2
1. Open a new form and change its name to ColourChanger. Place the following objects on this form.
 A heading label2 (Caption = Colour Changer)
 3 horizontal scroll bars (Set the max value property of all three to 255)
 3 other labels (2red, 3Green, 4Blue)  a command button to quit the form (Caption = Return)  another small label5 under the button with its visible property set to false.
2. Double click each scroll bar and add the following code to its _onChange() event. Use cut and paste to make the task easier.
Label1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label5.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label1.ForeColor = RGB(255 - HScroll1.Value, 255 - HScroll2.Value, 255 -
HScroll3.Value)
Label5.ForeColor = RGB(255 - HScroll1.Value, 255 - HScroll2.Value, 255 -
HScroll3.Value)
Label5.Visible = True
Label5.Caption = “WOW!”
Label2.BackColor = RGB(HScroll1.Value, 0, 0)
Label3.BackColor = RGB(0, HScroll2.Value, 0)
Label4.BackColor = RGB)0, 0, HScroll3.Value)
3. Double click the return button and add the following code to its _onClick() event
Unload Me
4. Use the Project Explorer window to return to your main form and double click
example 2 in your menu to add the appropriate code.
5. Use <F5> function key to test your project. Save and backup.

0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget