Upload
bloodyedge03
View
2.056
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Introduction to Visual Basic
Visual Beginners All-Purpose Symbolic Instruction Code
Visual Basic
• is a tool that allows you to develop Windows (Graphic User Interface - GUI) applications.
• is event-driven, meaning code remains idle until called upon to respond to some event.
Steps in Developing Application
1. Draw the user interface2. Assign properties to controls3. Attach code to controls
Draw the User Interface
Visual Basic operates in three modes.• Design mode - used to build application• Run mode - used to run the application• Break mode - application halted and debugger
is available
Getting Started
7 Windows
1. Main Window2. Form Window3. Toolbox4. Properties Window 5. Form Layout Window6. Project Window7. Code Editor Window
Main Window
• consists of the title bar, menu bar, and toolbar.
Form Window
• is central to developing Visual Basic applications. It is where you draw your application.
Toolbox• is the
selection menu for controls used in your application.
Properties Window
• is used to establish initial property values for objects.
Form Layout Window
• shows where (upon program execution) your form will be displayed relative to your monitor’s screen.
Project Window
• displays a list of all forms and modules making up your application.
Code Editor Window
• Contains the actual Basic coding.
Assign Properties to Controls
• Naming Convention of ControlsObject Prefix Example
Form frm frmHello
Command Button cmd, btn cmdExit, btnStart
Label lbl lblStart, lblEnd
TextBox txt txtTime, txtName
Menu mnu mnuExit, mnuSave
Check box chk chkChoice
Attach Code to Controls
• Code in a Visual Basic application is divided into smaller blocks called procedures.
• Event procedure syntax:
object name_event ()Ex. Command1_Click ()
Private Sub object name_event ()
End Sub _______________________________________
Private Sub Command1_Click ()
End Sub
Private Sub Command1_Click ()
object name.property = valueEnd Sub_______________________________________Private Sub Command1_Click ()
Text1.Text = "Hello, world!"End Sub
Variables
Rules used in naming variables:• No more than 40 characters.• They may include letters, numbers, and
underscore (_).• The first character must be a letter.• You cannot use a reserved word.
Data Types
Variable Declaration1. Default (variant)2. Implicit
Amount% = 3003. Explicit
four levels of scope• Procedure level• Procedure level, static• Form and module level• Global level
• Procedure levelDim Variable name as Data type
Ex. Dim Myint as integer• Procedure level, static
Static Variable name as Data typeEx. Dim Myint as integer
• Form and module levelDim Variable name as Data type
Ex. Dim Myint as integer• Global level
Global Variable name as Data typeEx. Dim Myint as integer
• Procedure Routine1 has access to __, __, and __(…..)
• Procedure Routine2 has access to __, __, and __(…..)
• Procedure Routine3 has access to __, __, and __(…..)
• Procedure Routine1 has access to X, Y, and A (loses value upon termination)
• Procedure Routine2 has access to X, Y, and B (retains value)
• Procedure Routine3 has access to X, Z, and C (loses value)