Download - Visual Basic Intro
![Page 1: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/1.jpg)
Introduction To Visual Basic 6
![Page 2: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/2.jpg)
Announcements
Thursday, Oct 9th, 7:30PM, C106 Lloyd Douglas (NSF) Diversity in Science-Who needs it? 5 extra credits.
About the extra credit Please submit printed copy. Don’t hand in through blackboard
system or send email.
![Page 3: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/3.jpg)
Programming language
Programming is writing instructions for a computer.
Level of programming languages Machine language – 0s and 1s Intermediate languatge – assambly
language. High level language – BASIC, C++…
![Page 4: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/4.jpg)
Interpreting or compiling
How do computers handle the high level language? Read and Interprete the code line by line
with an program called interpreter, e.g. BASIC.
Translate the language to machine code (executable files) with a program called compiler and run the program, e.g. C++.
Visual basic has both Interpreter and Compiler.
![Page 5: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/5.jpg)
History of BASIC
Basic --- Beginners' All-purpose Symbolic Instruction Code (May, 1964)
MS-BASIC 2.0 (July, 1975) Visual Basic 1.0 (May,1991) Visual Basic 6.0 (July 1998)
![Page 6: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/6.jpg)
Why do we learn Visual Basic
It shares the same principles with other programming languages.
It is good when developing small and handy utility programs.
It is supported by Microsoft. It is powerful when integrated with
Excel and Word.
![Page 7: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/7.jpg)
Six Steps in Programming
Problem Identification Solution Design Coding Compiling with compiler or running
with interpreter Debugging Testing
![Page 8: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/8.jpg)
Step 1 and 2: Problem Identification and Design
Identify what needs to be solved Make diagrams, and equations, etc
Design: Analyze the problem and develop an ALGORITHM and FLOWCHART
![Page 9: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/9.jpg)
Step 3: Source Code
Creating “Source Code” Source Code is the instructions for the
computer written in Visual Basic programming language
In VB, source code is linked to an object on the form
Designing user interface is also part of the coding.
![Page 10: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/10.jpg)
Step 4a:Compiling Compiling converts Visual Basic
source code to “executable” machine language - instructions the processor can understand (1s and 0s)
Creates .exe file Advantage:
Fast and small Disadvantage:
Debugging is inconvenient.
![Page 11: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/11.jpg)
Step 4b: Interpreting Interpreting reads and runs one line
of code each time. You can find “Grammar errors” in this
stage. Advantage:
Good for debugging Interpreter is easy to program.
Disadvantage: Slow
![Page 12: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/12.jpg)
Interpreting and Compiling in VB
![Page 13: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/13.jpg)
Step 5: Debugging
Debugging is removing the “functional errors” from your program
Running tells you where there are errors
Go back to source code and fix errors Save and re-run Repeat until errors are gone
![Page 14: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/14.jpg)
Step 6: Testing and Running
Try to run the program by pressing the start button
If it starts running, enter the answers and/or click the buttons to test it
Test your program with boundary and special cases.
![Page 15: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/15.jpg)
Visual Basic Programming
VB is a programming language that allows you to program in a Windows environment
You create a “Form” with several “Objects”
You set the properties of objects. You write event handler to response
to user’s input.
![Page 16: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/16.jpg)
VB programming
Project
Form 1 Form 2 Form 3
Text box Button
Picture box Objects
Text box
Button
Objects
![Page 17: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/17.jpg)
Definitions
Form contains the Main Program Controls are user interface elements
(text boxes, commands) in the Form Forms and Controls are referred to as
OBJECTS Objects have PROPERTIES (features
you can change)
![Page 18: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/18.jpg)
Forms in Visual Basic
You create a form that is your graphical user interface
Has places to input values Has buttons to click Has other user interface elements,
e.g. Menu, scroll bar…
![Page 19: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/19.jpg)
Objects in VB
Everything in VB is objects, forms, buttons,…
Three elements of objects. Properties Methods Event handlers.
Properties (size,Caption…)
Methods (Print…)
Event Handler (Command1_Click())
VB object
![Page 20: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/20.jpg)
Object: Dog Properties
Height, weight, color, emotion (friendly, hostile)…
Methods Barking, biting, wagging, singing…
Event handlers Owner coming in: call wagging, call singing,
emotion=friendly; Intruder coming in: call barking, call biting,
emotion=hostile.
![Page 21: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/21.jpg)
Important Controls
Text Boxes – area where you enter text
Command Buttons – you click on them to do something
Picture Boxes – Output your results.
![Page 22: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/22.jpg)
Text Boxes Properties:
Name (of object) Text (the words) Alignment (left, right, middle) Appearance BackColor (background) BorderStyle Font FontColor
![Page 23: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/23.jpg)
Command Button
Properties: Name BackColor Style (This controls the backcolor) Caption
![Page 24: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/24.jpg)
Picture Boxes
Properties Name Picture
Methods Print
![Page 25: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/25.jpg)
Definitions
ObjectsForms Command
Buttonproperties
propertiesproperties
propertiesproperties
propertiesproperties
propertiesproperties
propertiesMethods
propertiesproperties
MethodsTextbox
propertiesproperties
propertiesproperties
properties
propertiesproperties
propertiesMethods
Picture Boxproperties
propertiesproperties
propertiesproperties
properties
propertiesproperties
propertiesMethods
Label
propertiesproperties
propertiesproperties
propertiesproperties
propertiesproperties
propertiesMethods
Handlers
propertiesMethods
![Page 26: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/26.jpg)
“Design time” and “Run time”
When you design you can use the property window to set the property of certain object.
When you run the program, you can only use code to change the property of that object.
![Page 27: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/27.jpg)
Just a Bunch of Objects
Q: Now that you have a bunch of objects, how do you make them react to your command? A: Sub Procedures
Sub Procedures are the instructions Sub Procedures go with Events (Like
clicking a button)
![Page 28: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/28.jpg)
How the test program works
![Page 29: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/29.jpg)
How the test program works
MessageDispatching
Block User
Text box
Properties
Methods
Event Handler
Button
Properties
Methods
Event Handler
PictureBox
Properties
Methods
Event Handler
You have got letters.
You have got clicked.
![Page 30: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/30.jpg)
Making It Do Something
Want program to change on an “Event” Events:
MouseDown MouseUp Click
Need to create Sub Procedures Sub Procedure handles Event and
changes Properties of an Object
![Page 31: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/31.jpg)
Sub Procedure
Two Objects: Text1 and Command1Sub Procedure:Private Sub Command1_Click()
Text1.FontSize = 18
End Sub
When Command1 is clicked, the FontSize property of Text1 is changed to 18
![Page 32: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/32.jpg)
Sub ProcedurePrivate Sub CommButt_Click()
Text1.FontSize = 18
Text1.BackColor = vbBlue
Command1.Caption = "Get Some Now"
End Sub
![Page 33: Visual Basic Intro](https://reader036.vdocument.in/reader036/viewer/2022062407/563dba72550346aa9aa5b5fb/html5/thumbnails/33.jpg)
Homework Read Chapters 1 & 2 in book