+ All Categories
Home > Documents > Introduction 1. CIS 400 Programming for the Windows Environment 2.

Introduction 1. CIS 400 Programming for the Windows Environment 2.

Date post: 02-Jan-2016
Category:
Upload: joy-flowers
View: 217 times
Download: 3 times
Share this document with a friend
Popular Tags:
27
Introducti on 1
Transcript
Page 1: Introduction 1. CIS 400 Programming for the Windows Environment 2.

1

Introduction

Page 2: Introduction 1. CIS 400 Programming for the Windows Environment 2.

CIS 400

Programming for theWindows Environment

2

Page 3: Introduction 1. CIS 400 Programming for the Windows Environment 2.

VB History

FORTRAN IBM1957

BASICDartmouth

1964

BASICsMicrosoft

1975MS-DOS

1982

VB1991VB 1-6VBA

VB.NET2001

VB 7-10VBA

3

Page 4: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Visual Basic is one of four .NET applications (Visual C#, Visual C++, and Visual F#) included in Visual Studio.

The main components of the .NET Framework are the Class Library (containing the pre-written code) and Common Language Runtime (which manages the execution of .NET programs).

4

Page 5: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Visual Basic is an object-oriented,

event-driven language

5

Page 6: Introduction 1. CIS 400 Programming for the Windows Environment 2.

ObjectsButton

CheckBox

Label and TextBox

ListBox

6

Page 7: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Must begin with a letter.

Must contain only letters, numbers, and the underscore character (_).

Object Naming

Punctuation characters and spaces are not allowed.

Must be no longer than 40 characters

7

Page 8: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Object Naming ConventionForm frm frmFileOpen

Check box chk chkReadOnly

Command Button cmd cmdExit

Label lbl lblWind

List box lst lstState

Text box txt txtLastName

Vertical Scroll Bar vsb vsbTemp

Option (Radio) Button opt optAC

Picture Box pic picJeep8

Page 9: Introduction 1. CIS 400 Programming for the Windows Environment 2.

An event is an action performed on an object. Event-driven subroutines are always in the form: object_Event

The subroutine “handles” the event that happens to the object.

Events

9

Page 10: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Objects EventsClick

CheckChanged

Leave

MouseEnter

10

Page 11: Introduction 1. CIS 400 Programming for the Windows Environment 2.

A property is an attribute associated with an object. Using the dot form:

object.Property

Properties can be assigned during design or run time.

Properties

11

Page 12: Introduction 1. CIS 400 Programming for the Windows Environment 2.

PropertiesObjectsText

BackColor

ReadOnly

SelectionMode

12

Page 13: Introduction 1. CIS 400 Programming for the Windows Environment 2.

A method is like a procedure, except that it is tied to an object (control or form), just like a property. In other words, a property is made up of data

attached to the object, and a method is a procedure attached to the object. Unfortunately, methods also use the dot form: object.Method

Methods

13

Page 14: Introduction 1. CIS 400 Programming for the Windows Environment 2.

There are two ways to tell methods and properties apart.

Methods are usually verbs (denoting action) like Hide or Select:

frmMain.Hide()

Properties are descriptive like ForeColor or Text:

lblLetterGrade.Text="A"14

Page 15: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Furthermore, a method is invoked by simply using the method statement. frmGetFile.Show()

Whereas an object property is only part of a statement such as assignment.

txtTemp.BackColor = Color.Red

15

For additional predefined colors, see: Color List and Color Table

Page 16: Introduction 1. CIS 400 Programming for the Windows Environment 2.

For some methods, you must specify the class from which it is called and the syntax is different.

Result = Math.Round(3.1415965,2) txtSubtotal.Text = Convert.ToString(subtotal)

See pages 119 & 127 in the text for additional Math & Convert class methods.

Class.Method(arg(s))

16

Page 17: Introduction 1. CIS 400 Programming for the Windows Environment 2.

int fff ( . . . )Local Items . . .

Global Items (variables & constants)

int main() . . .

c/c++

execution begins here

Preprocessor Directives(includes)

17

Page 18: Introduction 1. CIS 400 Programming for the Windows Environment 2.

VISUAL

BASI C

FORM(s)Form Level Items

Local ItemsFunctions or Procedures

MODULE(s)

Project or Module Level Items

Functions or Procedures

Local Items

Where doesexecution begin?

18

Page 19: Introduction 1. CIS 400 Programming for the Windows Environment 2.

APPLICATIONPROJECT

FORM1.VBFORM2.VB...

MODULE1.VB

EDITOR

APP.EXEAPP.EXE

COMPILER

Syntax Errors

DEBUGGER

Run-timeErrors

(Exceptions)

LogicErrors

EDITOR

19

Page 20: Introduction 1. CIS 400 Programming for the Windows Environment 2.

VB Project Files

Solution (.sln)

Project (.vbproj)

Form (.vb)

Plus several others

Application (.exe)

20

Page 21: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Let’s begin by

looking at a simple

interest program

written in c++

and Visual Basic.

21

Page 22: Introduction 1. CIS 400 Programming for the Windows Environment 2.

22

#include <iostream.h> int main(void) { float principle,rate,time,interest; cout << "Principal --> "; cin >> principle; cout << "Rate --> "; cin >> rate; cout << "Time --> "; cin >> time; interest = principle * rate * time; cout << "Interest is " << interest; cout << endl; return 0; }

c++

Principle --> 1000Rate --> 5Time -->3Interest is

What is wrong with this?

Page 23: Introduction 1. CIS 400 Programming for the Windows Environment 2.

23

VB

Page 24: Introduction 1. CIS 400 Programming for the Windows Environment 2.

The full “Professional” version of Visual Studio 2010 has been installed on computers located in Chase 215. You can download a free copy of Visual Basic 2010 Express at:

http://www.microsoft.com/visualstudio/eng#downloads+d-2010-express

24

Page 25: Introduction 1. CIS 400 Programming for the Windows Environment 2.

VB Environment

25

Let’s design the interface and create the code for the

simple interest program

Page 26: Introduction 1. CIS 400 Programming for the Windows Environment 2.

We could:

26

Test for valid textbox contents:Non-emptyOnly numeric characters

We could add:Additional instructions - %A Clear button

Page 27: Introduction 1. CIS 400 Programming for the Windows Environment 2.

Read the

Description

Of Assigment-1

27


Recommended