Visual Basic 2008 The programming part

Similar documents
Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Visual Basic 2008 Anne Boehm

LESSON B. The Toolbox Window

Chapter 2 Visual Basic Interface

Using Visual Basic Studio 2008

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

Microsoft Visual Basic 2005: Reloaded

Unit E Step-by-Step: Programming with Python

I101/B100 Problem Solving with Computers

Lab 7 Macros, Modules, Data Access Pages and Internet Summary Macros: How to Create and Run Modules vs. Macros 1. Jumping to Internet

Visual Basic Program Coding STEP 2

Chapter 2 Exploration of a Visual Basic.Net Application

HOUR 4 Understanding Events

Lab 3 The High-Low Game

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Procedures (Subroutines) and Functions

Visual Programming 1. What is Visual Basic? 2. What are different Editions available in VB? 3. List the various features of VB

Microsoft Visual Basic 2005: Reloaded

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Your First Windows Form

Chapter 2 Visual Basic, Controls, and Events. 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events

STUDENT LESSON A1 Introduction to Object-Oriented Programming (OOP)

Decision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop

GUI Design and Event- Driven Programming

REVIEW OF CHAPTER 1 1

Using the TekScope IVI-COM Driver from C#.NET

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

CALIFORNIA STATE UNIVERSITY, SACRAMENTO College of Business Administration. MIS 15 Introduction to Business Programming. Programming Assignment 3 (P3)

Learning VB.Net. Tutorial 17 Classes

STUDENT LESSON A5 Designing and Using Classes

Software and Programming 1

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

KEYWORDS DDE GETOBJECT PATHNAME CLASS VB EDITOR WITHEVENTS HMI 1.0 TYPE LIBRARY HMI.TAG

bash Scripting Introduction COMP2101 Winter 2019

3. NetBeans IDE 6.0. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

IT 374 C# and Applications/ IT695 C# Data Structures

My First iphone App. 1. Tutorial Overview

Please answer questions in the space provided. Question point values are shown in parentheses.

Civil Engineering Computation

UEE1302 (1102) F10: Introduction to Computers and Programming

Chapter 2 Basic Elements of C++

Procedures in Visual Basic

Make View: Check Code

Lab # 2. For today s lab:

Computer and Programming: Lab 1

MODULE VI: MORE FUNCTIONS

Full file at

CS 211 Programming Practicum Fall 2018

My First iphone App (for Xcode version 6.4)

Applications with Multiple Forms

Basant Group of Institution Power Point Question

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET

Software and Programming 1

Tutorial 03 understanding controls : buttons, text boxes

Chapter 2, Part I Introduction to C Programming

Working with JavaScript

Higher Computing Science Software Design and Development - Programming Summary Notes

Call: Crystal Report Course Content:35-40hours Course Outline

COMP 202 Java in one week

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Chapter 10 Introduction to Classes

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Introduction to C Programming. What is a C program?

Lab # 02. Basic Elements of C++ _ Part1

Perl Basics. Structure, Style, and Documentation

Lecture 18 Tao Wang 1

Microsoft Visual Basic 2015: Reloaded

CS Final Exam Review Suggestions - Spring 2014

1. Create your First VB.Net Program Hello World

MS Access Part 1 (One Day Workshop) Khader Shaik

Introduction to Python Code Quality

Not For Sale. Using and Writing Visual Basic for Applications Code. Creating VBA Code for the Holland Database. Case Belmont Landscapes

20. VB Programming Fundamentals Variables and Procedures

Lesson 2: First Java Programs

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

Lab 1: Getting Started With Android Programming

Part 4 - Procedures and Functions

A student was asked to point out interface elements in this code: Answer: cout. What is wrong?

Code::Blocks Student Manual

ITP 342 Mobile App Dev. Interface Builder in Xcode

Design Of Human Computer Interfaces Assignment 1- Hello World. Compliance Report

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

SAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik

DEVELOPING OBJECT ORIENTED APPLICATIONS

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

FLIR Tools+ and Report Studio

FOR 240 Homework Assignment 4 Using DBGridView and Other VB Controls to Manipulate Database Introduction to Computing in Natural Resources

Chapter 2 First Java Programs

M Introduction to Visual Basic.NET Programming with Microsoft.NET 5 Day Course

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

BASIC ELEMENTS OF A COMPUTER PROGRAM

Lecture Set 2: Starting Java

Tutorial No. 2 - Solution (Overview of C)

Transcription:

Visual Basic 2008 The programming part Code Computer applications are built by giving instructions to the computer. In programming, the instructions are called statements, and all of the statements that make a program function are called the program code. Visual Basic is an Object Oriented Programming (OOP) language. OOP code is organized into classes, each class defining a set of data and actions. Classes are used to generate objects. You used Control classes to create interfaces already. Event Procedures Events are the actions that occur when the application runs. An event can be a mouse click, a keystroke, or a control response. Once you design GUI, you must write code that responds to events. In a way, each event procedure is like a miniature program that you write for each control whose event should cause on action to take place. Procedures perform specific tasks in response to a user interaction with an object and are written within a class. Code Statements Code statements are written in the Code window, using Visual Basic's own programming language syntax (which is similar to Liberty BASIC). When you open the Code window you will find code already in place such as: Syntax: Form Public Class Form1 End Class To open the Code window, click on View Code or select the View Code button on the Solution Explorer window.

Class statement: used to define a class Begins with Public Class <class name> Ends with End Class Class Name list box: lists the names of objects (controls) included in the user interface Method Name list box: lists the events to which the selected object is capable of responding When you select a control from the Class Name list box and a method name, a code template for the event appears in the Code Editor window. The class will need statements that will tell the computer what it is to do before your program will do anything. (A class by definition is a data type that can store data and includes a set of statements that perform a well defined task). Procedures A procedure is a block of code written to perform the specific tasks of a program solution. In a way, each event procedure is like a miniature program that you write for each control that needs to respond to the end user of the program. Event procedures are added to a class and contain no statements to begin with, just a blank area where the programmer will code statements. In the Code window, event procedures can be added by selecting the object name in the Class Name list and the event from the Method Name list. In Designer window, double clicking on the object will open the Code window with an event procedure that selects the most common method for that object. For instance, the mouse common method for a Button is the click event, which executes in response to a mouse click. For example: Syntax: Procedures Public Class frmmainform Private Sub ObjectName_Event(ByVal sender As Object, ByVal e As System.EventArgs) Handles Object Name.Event End Sub End Class Statements

Private indicates that the procedure cannot be seen outside of the frmmainform class. ObjectName is the selected object, it could be a control or a form. Text boxes are one class of objects. Event is the event name, it could be a click (mouse click). Sub declares the procedure. End Sub is required to end the Sub statement. The procedure heading that is generated by VB contains a set of parentheses with arguments that are used by the procedure. It is extremely important to not change the arguments at this time. Every program must contain commands for input and output in order to be interactive. Well written code is clear and easy to understand. This makes debugging and modification easier. The IDE automatically indents code for readability, but you may use the Tab key as we.. Properly indented code is good programming style. Methods A method is a procedure in a class. Visual Basic includes several built in methods for use within your application. These predefined instructions can be used to manipulate data or terminate a program. Commenting code In order to make maintenance of your code more manageable, include comments. Commenting vague or misleading code can be accomplished using single quotation marks ( ) to begin the comment.

Lab #2 Adding Code Open the Wizard Application solution that you created in Lab #1 Open the Code window From the drop-down menus, select the cmdexit Button and the Click Event. To close a form in a running program, the syntax Me.Close ( ) will accomplish this. Me is a keyword that refers to the current form. The Close Method closes the form. This will terminate a program if it has just one form. To end the running of a program, the syntax Application.Exit ( ) will accomplish this. Application refers to the application that you have created and the Exit Method closes out the program. In between the Private Sub and the End Sub Statements, type: Me.Close ( ) Run the program and click on the Exit button to ensure that this code works.

Intellisenses A special context-sensitive menu (the IntelliSense menu) appears when you start typing some things in the Code window. This menu shows the code that is available to you. It guesses what you need based on what you are doing. Assignment Statements Assignment statements in a procedure are used to change a value at run-time. One use of an assignment is to change the property of an object. To do this, the following syntax is used: Syntax: Assignment Statements ControlName.Property = value We will set the picture of the wizard to hide when the Hide button is clicked and show when the Show button is clicked. In the Designer view, double click on the Hide button. The Code view should open with the cmdhide_click procedure showing. In between the Private Sub and the End Sub Statements, type: picwizard.visible = False Run the program and click on the Exit button to ensure that this code works. From the drop-down menus, select cmdshow and the Click event. In between the Private Sub and the End Sub Statements, type: picwizard.visible = True Run the program and click on the Exit button to ensure that this code works. Note: if your program does not run, check on the names of your objects, ensuring that you have named them as you were asked to. Also, check that you have typed code properly in the proper locations. Add comments to your code.

Your program code should look something like the following: Note the yellow and green bar on the side of the code. The yellow bar is code that was added, but never debugged. The green bar indicates code that has been tested and works.