27
Introduction to Visual Introduction to Visual Basic Basic

Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Embed Size (px)

Citation preview

Page 1: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Introduction to Visual BasicIntroduction to Visual Basic

Page 2: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Quick LinksQuick Links

• Windows Application Programming

• Event-Driven Application

• Becoming familiar with VB

• Control Objects

• Saving and Running an Application

• Opening and Closing a Project

Page 3: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

• An application contains program code which are instructions that tell a computer how to perform a specific task

• Each line of code is called a statement

• Most programs you use contain millions of statements and are usually written by teams of programmers

• VB writes a lot of code for you! This code generates the initial form and sets the default properties of the form.

Program CodeProgram Code

Page 4: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Program Code Cont’dProgram Code Cont’d

• Also, when you draw in a control object in the design window, such as a button, VB generates code automatically to create that object; the code for the object’s functionality is left to you

• You can get to the code window by using the Solution Explorer Window or by double clicking any object in the form, including the form itself

Page 5: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Visual Basic FactsVisual Basic Facts

• BASIC is actually an acronym and stands for Beginner's All-purpose Symbolic Instruction Code

• BASIC is an old programming language; the “Visual” part has been added recently to make it easier to create powerful windows applications

Page 6: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Event-Driven ApplicationEvent-Driven Application• A Visual Basic application is event driven

• An event occurs when the user interacts with the application. For example, when a user clicks a button, this is an event

Page 7: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Event Driven Application Con’tEvent Driven Application Con’t

• An event-driven application waits for an event to occur before executing code

• When an event occurs, only the code written to handle that event is run

• For example, in the simple program below, when the ‘Exit’ button is pressed, the code for that button is executed. If the code is properly written, pressing the button should close the program

Page 8: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Visual Basic InterfaceVisual Basic Interface• The Visual Basic interface consists of two

parts: a graphical interface (“Visual”) and the program code (“BASIC”)

graphical interface (“Visual”)

program code (“BASIC”)

Page 9: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Becoming Familiar with Visual Basic .NET

Page 10: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Creating a New ProjectCreating a New ProjectClick on File>New>Project to bring about the New Project Dialog Box as seen below

Page 11: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Properties Window

The Design WindowThe Design Window

ToolboxSolution Explore

r Window

Design Windo

w

Page 12: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

The Design Window Con’tThe Design Window Con’t• The Design window displays the

application interface where objects are added, deleted, and sized

• The Toolbox contains controls that are used to create objects

• The Solution Explorer window is used to switch between the Design and Code windows

• The Properties window lists the properties of a selected object

Page 13: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

The Windows FormThe Windows Form• A windows application uses at least one form

• A form is where you design your user interface and put controls such as buttons and textboxes

• A form can be resized by using the control handles

•A form has properties that define its appearance and behavior

Page 14: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Form PropertiesForm Properties• We can change the properties of our form

by selecting the form (click on it) and changing whatever property we want in the Properties Window

Page 15: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Control ObjectsControl Objects

• Control objects are objects that we can place on our form to create a user interface

• An user interface is a way of getting input from the user and providing output to the user

• Some control objects are meant to get user input such as a textbox; other objects are used for output such as labels

Page 16: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

The Label Control ObjectThe Label Control Object

• The label control displays text that cannot be changed by the user

• The label control is used as an output to display messages to the user

Label

Page 17: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Creating a Label ControlCreating a Label Control

• Click on the Label control in the toolbox

• When you place the cursor over the form, the cursor changes

• Click and drag to draw the label

• The grid on the form is used to help you create your interface, but does not show up in the final program

Page 18: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Label PropertiesLabel Properties

The label control has the properties

• Name identifies the label for you as the programmer; the user never sees this name

• Text is the message you wish to display to the user

• Font allows you to change the appearance and font settings of the message you display to the user

• TextAlign allows you to set the alignment of text in a label. For example, TopLeft, TopCenter…

Page 19: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Setting Label PropertiesSetting Label Properties

Page 20: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Just to Give You an IdeaJust to Give You an Idea

labels can be used in conjunction with textboxes to get input from

the user

Page 21: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

The MainMenu ControlThe MainMenu Control• A Windows application usually includes

menus that contain commands

• A menu is added to an interface by clicking the MainMenu control in the toolbox and then clicking on the form

• A menu is automatically added to the interface and a MainMenu component is added to the component tray at the bottom of the Design Window

Page 22: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Working with MainMenusWorking with MainMenus

• Click where it says, “Type Here” on the menu in the form to enter commands such as ‘File’, ‘Edit’

• When a command or menu name is typed, another box is automatically added to allow for more commands and menus

• Only the command and menu names that were typed by you will show up at run-time

Page 23: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

MainMenu PropertiesMainMenu Properties

• Name identifies the menu and commands for you as the programmer; the user never sees this name

• Text is the menu or command name and is set by clicking on the ‘Type Here’ text on the menus in the design window

Page 24: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Saving and Running an ApplicationSaving and Running an Application

• Save your work often during development to avoid losing changes

• To run your program, which you should do often to test what you’ve done, click on the ‘Start’ button

• If your program has no errors, pressing this button should run your program. Now you can see and use your program as a user would see and use it. You can test its functionality by interacting with it the way you intend a user to interact with it

Page 25: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Saving and Running an Saving and Running an Application Con’tApplication Con’t

• To return to the design window to continue development, simple close the running program (click the ‘x’ in the top right corner of your application)

Page 26: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

What is Really Happening?What is Really Happening?• What really happens when you click the

‘Play’ button?

• First, the code that you, the programmer writes, is converted into a language that the computer understands in a process called compiling

• During the compiling process, your program code is checked for syntax errors

• If there are no syntax errors in your code, VB .NET then builds your application

• More on all this later…

Page 27: Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and

Intro to Visual Intro to Visual BasicBasic

Closing and Opening a ProjectClosing and Opening a Project

• To save your work, click File>Save <Form Name>.vb

• To close a project, click File>Close Solution

• To open a project, click File>Open>Project. Then Navigate to find your project in the Open Project Dialog Box.