Download presentation
1
The Initial Visual Basic Screen
Menu bar Project Explorer window Toolbar Toolbox Properties window Description pane Form Project Container window Form Layout window
2
Steps to Create a Visual Basic Program
1. Create the interface by placing controls on the form 2. Set properties for the controls and the form 3. Write code for event procedures associated with the controls and the form
3
Placing a Text Box on a Form
Double-click on the text box icon in the toolbox to add a text box to your form Activate the properties window (Press F4) Set values of properties for text box Go over resizing and dragging the text box The first line of the properties window (called the object box) reads “Text1 TextBox” . Text1 is the current name of the textbox. The two Tab permit you to view the list of properties either alphabetically or grouped by categories.. We discuss four properties : The Text property determines the words in the text box. Press Shift+Ctrl+F to move to the first property beginning with F . Move to the property ForeColor. The foregroung color is the color of the text.. Click on Palette tab to display a selection of colors. Highlight the Font property and change it to Italic
4
Placing a Text Box on a Form
5
Private Sub cmdPush_Click. ‘Display the ‘Hello World’ Message
Private Sub cmdPush_Click ‘Display the ‘Hello World’ Message lblMessage.Caption = “Hello World” End Sub *********************************************** Private Sub cmdExit_Click ‘Exit the project End End Sub Comment Assignment
6
Naming Objects:
7
Visual Basic Events Code is a set of statements that instruct the computer to carry out a task. Code can be associated with events When an event occurs, the code associated with that event (called an Event Procedure) is executed. When a VB program is run, a form and its controls appear on the screen. Normally, nothing happens until the user takes an action, such as clicking a control or pressing the Tab key. Such an action is called event.
8
Creating An Event Procedure
Double-click on an object to open a Code window. (The empty default event procedure will appear. Click on the Procedure box if you want to display a different event procedure.) Write the code for that event procedure. Object Property Setting frmWalkthrough Caption Demonstration txtPhrase Text (blank) cmdBold Caption Make Phrase Bold Object Box Procedure Box: Contains a list of all possible event procedures associated with the text box Choose txtPhrase_LostFocus() txtPhrase.Font.Size = 12 End Sub Choose GotFocus and type: txtPhrase.Font.Size = 8 txtPhrase.Font.Bold = False Go to command Button and choose cmdBold_Click and type txtPhrase.Font.Bold = True
9
Example of An Event Procedure
Private Sub objectName_event ( ) statements End Sub Private Sub txtOne_GotFocus( ) txtOne.Font.Size = 12 txtOne.Font.Bold = False The word Sub signals the beginning of the event procedure, and also identifies the Object and the event occurring to that object The word private indicates that the event procedure cannot be invoked by an event from another procedure. The word Sub means subprogram Example: the event procedure private Sub cmdButton_Click () txtBox.Text = “” End Sub The event clicking cmdButton is different from the event clicking picBox_Click
10
More Examples Private Sub cmdButton_Click( ) txtBox.ForeColor = vbRed
txtBox.Font.Size = 24 txtBox.Text = “Hello” End Sub Each color can be identified by a sequence of digits and letter beginning with &H. &HFF& = Red &HFF00& = Green &HFF000& = Blue
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.