Upload
joy-flowers
View
219
Download
3
Tags:
Embed Size (px)
Citation preview
1
Introduction
CIS 400
Programming for theWindows Environment
2
VB History
FORTRAN IBM1957
BASICDartmouth
1964
BASICsMicrosoft
1975MS-DOS
1982
VB1991VB 1-6VBA
VB.NET2001
VB 7-10VBA
3
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
Visual Basic is an object-oriented,
event-driven language
5
ObjectsButton
CheckBox
Label and TextBox
ListBox
6
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
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
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
Objects EventsClick
CheckChanged
Leave
MouseEnter
10
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
PropertiesObjectsText
BackColor
ReadOnly
SelectionMode
12
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
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
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
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
int fff ( . . . )Local Items . . .
Global Items (variables & constants)
int main() . . .
c/c++
execution begins here
Preprocessor Directives(includes)
17
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
APPLICATIONPROJECT
FORM1.VBFORM2.VB...
MODULE1.VB
EDITOR
APP.EXEAPP.EXE
COMPILER
Syntax Errors
DEBUGGER
Run-timeErrors
(Exceptions)
LogicErrors
EDITOR
19
VB Project Files
Solution (.sln)
Project (.vbproj)
Form (.vb)
Plus several others
Application (.exe)
20
Let’s begin by
looking at a simple
interest program
written in c++
and Visual Basic.
21
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?
23
VB
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
VB Environment
25
Let’s design the interface and create the code for the
simple interest program
We could:
26
Test for valid textbox contents:Non-emptyOnly numeric characters
We could add:Additional instructions - %A Clear button
Read the
Description
Of Assigment-1
27