43
Introduction to VB.NET

Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Introduction to VB.NET

Page 2: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Programming Basics Program / Application – A set of instructions that a

computer uses to do something. Programming / Developing – The act of creating or

changing a program Programmer / Developer – A person who makes a

program Run / Execute – The act of using a program Source Code – Code written in a programming language

by a developer.

Every program was created by someone Computers use special languages Programmers use special languages to create or change

a program

Page 3: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Introduction to Visual Basic .Net

Visual Studio 2012 .Net (VB.Net) is a programming language created by Microsoft. http://msdn.microsoft.com

Many programmers use VB.Net VB.Net is an object-oriented language.

Page 4: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Impact on Visual Studio 2012

Visual Studio 2012 is old technology Visual Studio 2012 will still be used for

many years to maintain existing programs The future of Visual Basic development is

Visual Studio 2012 .NET

Page 5: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Integrated Development Environments (IDEs) IDEs are programs designed to make programming

easier. Graphical Interface is intuitive Program management is easier Source code is easier to read Errors are easier to fix Too many features to list!

You do not need an IDE to create a program. But they are very helpful.

There are a few different IDE’s for VB.Net. But most VB.Net developers use Visual Studio 2012 .Net. (VS.Net)

Page 6: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

First Look at VS.NET

Options you can look at

Different windows youcan use

Page 7: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Setting Up Your Environment You can save files to the C Drive You must save files to the P Drive We want to organize our files on the P Drive

Use good names Keep related files in the same location

To tell VS2012.Net to use your P Drive1. Start VS2012.Net2. Go to FILE -> NEW -> Project or Ctrl + Shift + N3. On the Location: (You can setup your file location the and

select if it is C drive or P drive)4. You can rename your file on the Name: (Use good names)5. Click OK button

Page 8: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Setting up VS2012.Net

Page 9: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Class Exercise

Start VS2012.Net Setup VS2012.Net to save to a directory

on your P drive

Page 10: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

How to Make and Run a Program1. Create a new project

1. Click on FILE tab2. Select New -> Project or Ctrl + Shift + N3. Enter “HelloWorld” as the name of the new

project.4. Make sure that the Windows Application

template is selected.5. Click the OK button

2. Start the application 1. Click on FILE -> Open -> Project/Solution2. Select your file (.sln for solution)

Page 11: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

How to Make and Run a Program HelloWorld

Page 12: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Class Exercise

Create a Windows Application The name of the Windows Application is

HelloWorld Run the program

Page 13: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Solutions and Projects Solution – An organizer

for projects. A solution can contain

many projects

Project – An organizer for a program. A project can include

many files.

Examples of how Solutions and Projects work together

Molisi Management Solution Customer Project Financial Project Manager Project

Homework 1 Solution Program 1 Program 2

Homework 8 Solution Big Program

Page 14: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Solutions and Projects To make a new solution,

go to File -> New -> Blank Solution A solution can contain

many projects

To make a new project, go to File -> New -> Project A project can include many

files.

The same window is used for creating Solutions and Projects

Make sure thecorrect itemIs selected

Page 15: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Projects There are many

different kinds of project we can make.

This class focuses on Windows Applications

Can choose to add to the current solution or create anew solution

Make sure yourproject is savedin the correct folder

Page 16: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Best Practices

Keep your Solution and Project names simple and descriptiveGood Examples: Assignment5, Bank,

CustomerBad Examples: ILoveYou, IMissYou,

INeedYou Don’t use spaces in your names

Page 17: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Creating Solutions and Projects

Page 18: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Adding Forms to a Project

A form is a window To add forms to a

project:1. Project -> Add

Windows Form2. Enter the name of the

new form

Page 19: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Adding Projects to a Solution

To add projects to a solution:1. Solution Explorer ->

Right Click -> Add -> New Project

2. Select the project type3. Enter the name of the

new form

Page 20: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Adding Forms to a Project andAdding Projects to a Solution

Page 21: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Setting Startup Projects

A solution may contain more than 1 project

To tell Visual Studio .NET which project should be started when the solution is run: Solution Explorer -> Project

Name -> Set as Startup Project

Page 22: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Setting Startup Objects Often, your project has more than 1 object that can be started To tell Visual Studio .NET which object should be started when the

program is run: Project Tab -> Set as Startup Project

Page 23: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Selecting a Startup Project and Selecting a Startup Object

Page 24: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Stumbling Blocks

You can’t change properties when a program is running

If you rename a file, make sure you keep the .vb extension

Make sure you’re saving to the P drive. (Your personal share)

Page 25: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Class Exercise

Create a solution called MyFirstSolution Create 2 projects inside MyFirstSolution Each project will have 2 forms All 4 forms will have different colors Practice Running each different form

Page 26: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Behind the Scenes - 1 All files are stored on the computer The location is determined by your

settings 2 Folders exist

Bin – Contains the files needed to run the program To give the program to someone

else, copy these files to their computer

The running the .exe file will begin the program

Obj – Contains the files needed to debug (fix) the program These are useful when fixing errors

in a program When you start the application this

way: Click on Debug -> Start menu item, files are automatically created for you in both folders

Page 27: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Creating, Deleting and Executing Files Behind the Scenes

Page 28: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Behind the Scenes - 2 All files are stored on the computer The location is determined by your settings Solutions and Projects use different files

Solutions <SolutionName>.sln <SolutionName>.suo

Projects AssemblyInfo.vb <ProjectName>.vbproj <ProjectName>.vbproj.user

The organization of the files is determined by the order that you create the solutions and projects in

Page 29: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Viewing Solution and Project Files

Page 30: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Behind the Scenes - 3 The organization of the files is

determined by the order you create solutions and projects:

From a clean start: If a solution is created first, a

folder is created The solution’s name is the name

of the folder The solution’s files are inside

this folder If a project is added to the

solution, a folder is created inside of the solution folder The project’s name is the name

of the folder The project’s files are inside this

folder

Page 31: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

File Organization when Solution is Created First

Page 32: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Behind the Scenes - 4 The organization of the

files is determined by the order you create solutions and projects:

From a clean start: If a project is created first, a

folder is created The project’s name is the

name of the folder The project’s files are

inside this folder The solution’s files are

also inside this folder

Page 33: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

File Organization when Project is Created First

Page 34: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Class Activity

What will happen for these different solution / project creation scenarios?

Page 35: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Continuing Work on a Program Always open your Solution or Project file.

Solution files: .sln Project files: .vbproj Some files depend on other files. If you only open a

.vb file, your references may not be correctly setup. Therefore, your application may not work.

If you open a project file without a solution file: The solution files are automatically created You will be asked to save the files when you exit VS

.Net

Page 36: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Show how Solution files are automatically created

Page 37: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

VS.NET Windows - 1

How do we write programs?Write the code Fix any errors

Bug - An error in a program Debug – The act of removing errors from a program

Many windows are available to help you create code and debug your programs better

Page 38: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

VS.NET Windows - 2 Solution Explorer

Shows all the projects in your solution Shows all the files in each project

ToolBox Allows you to add controls to your form

Properties Allows you to change object properties

Task List Shows all current syntax errors Tracks pending changes and additions to code

‘Todo Right Click on column header and go to Show Tasks

to change what is displayed

Page 39: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

VS.Net Windows

Page 40: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Managing Your Windows

Windows can dock in different parts of your screen

Many windows docked in the same location are organized with tabs

The pin allows you to choose whether you want the windows to hide when you are not using them

Only show the windows you want to use!

Tabs

Docked Windows

Page 41: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Managing Windows

Page 42: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

VS.NET Features

Outlining #Region “RegionName” #End Region

Intellisense Helps you choose the word you want to type Ctrl + Space

Autocode Creates code automatically for you Use ComboBoxes in code view

Lines to Separate Methods

Page 43: Introduction to VB - TIHE - IntroductionToVB.pdf · Integrated Development Environments (IDEs) IDEs are programs designed to make programming easier. Graphical Interface is intuitive

Demonstration

Other VS.Net Features