Developer Data Modeling Mistakes: From Postgres to NoSQL
Chapter 1
1. Chapter One:
Event Drive Fundamentals:
1.1 What’s an event driven program?
1.2 Working in the Programming Environment
1.3 Building Your First Application
1.4 Using the intrinsic/basic/ controls
1.5 Working with Properties, Methods, and Events
1.6 Working with Projects in event driven Programming
UOG, IS Department Ins. G/M 1
2. 2
1.1 What’s an event driven
program?
What are Events?
• An event can be defined as a type of signal
to the program that something has
happened.
• The event is generated by external user
actions such as mouse movements, mouse
clicks, and keystrokes, or by the operating
system, such as a timer.
3. What’s an event driven program?
Visual Basic falls into a category of programming
referred to as event-driven programming.
Event-driven programs respond to events from
the computer, such as the mouse button being
pressed.
The designer uses ready-made objects such as
Command Buttons and Textboxes, to build user
interfaces that make up the application.
This approach to programming drastically reduces
the amount of code required to develop a Windows
application.
UOG, IS Department Ins. G/M 3
4. …
Visual Basic is event-driven, meaning code
remains idle until called upon to respond to some
event (button pressing, menu selection ...).
Visual Basic is governed by an event processor.
Nothing happens until an event is detected. Once
an event is detected, the code corresponding to
that event (event procedure) is executed.
Program control is then returned to the event
processor.
UOG, IS Department Ins. G/M 4
5. 1.2. Working in the Programming Environment
Default Environment Settings
The full version of Visual Studio 2010 provides an
option to allow the programmer to select the
default profile for the IDE. The first time you open
VisualStudio, you are presented with the Choose
Default Environment Settings dialogbox, where
you can chooseVisual Basic Development Settings.
Notice the instructions in the dialog box: you can
make a different selection later from theTools
menu.
Note: If you are using the Express version of
Visual Basic, you won’t see this dialog box.
UOG, IS Department Ins. G/M 5
9. …
Title Bar: The top line is called the Title bar, it
includes the project name and icons to minimize,
maximize and close the project
Menu Bar: The second line is called the Menu bar.
Selecting one of the choices (File, Edit, View,
Project, Format… Help) causes one of drop-down
menus to appear. The user can select required
menu.
Tool bar: The third line is called the Standard Tool
bar. The icons on this line duplicate several of the
more commonly used menu items. It acts as a
short cut to select the menu
UOG, IS Department Ins. G/M 9
10. …
Form design and project container windows: The
Form design window is where the user interface
is actually designed by placing the controls from
Tool Box. Each control can be moved, resized and
its properties can be assigned using Properties
Window.
Tool box: The Toolbox contains commonly used
controls. A control can be selected and placed in
the Form by double clicking on the control or by
clicking once on the control, then clicking on the
desired location within the form. The associated
code can be viewed or edited by double clicking
on the control
UOG, IS Department Ins. G/M 10
11. …
Properties window: Each Object has its own unique list
of properties. The Properties Window allows assigning
or changing the properties.
Project window: The Project Window displays a
hierarchical list of the files associated with a given
project.
Form layout window: This window specifies the screen
location of the forms within a project, the location can
be changed by dragging the form icon to the desired
position
Immediate window: This window is very useful for
debugging a project. Whenever a variable or
expression is entered, the corresponding value will be
shown immediately
UOG, IS Department Ins. G/M 11
12. 1.3 Building Your First Application
Developing VB projects
To develop VB projects, the three steps process for
planning the project and then repeat the process for
creating the project is to be done.
Planning
Design the User Interface: Draw the forms and controls
with the names
Plan the Properties: Specify the properties of all controls
to set or change during the design of the form
Plan the basic code: Plan the procedures to be executed
when the project runs. Write the pseudo code, which
is an English expression or comment the part that
describes the action.
UOG, IS Department Ins. G/M 12
13. …
Programming፡
Define the User Interface : Create the forms
and controls designed in the planning stage
Set the Properties : Define the properties of the
controls
Write the Visual Basic code : Write VB
programming statements to carry out the
actions needed.
UOG, IS Department Ins. G/M 13
14. Object’s Properties Can Be Set In Two Ways
1. Setting Properties of Objects at Design Time
Properties can be changed by typing a new
value or choosing from a list of predefined
settings (available as a drop down list) in
Properties Window. A very important property
for each object is its name. The name is used
by Visual Basic to refer to a particular object in
code.
UOG, IS Department Ins. G/M 14
15. …
2. Setting Properties at Run Time:
You can also set or modify properties while your
application is running. To do this, you must
write some code. The code format is:
ObjectName.Property = NewValue
Such a format is referred to as dot notation. For
example, to change the BackColor property of
a form name frmStart, we'd type:
frmStart.BackColor = BLUE
UOG, IS Department Ins. G/M 15
16. 1.4 Using the intrinsic controls
There are about 20 controls which are built in
to VB. These controls are called intrinsic
controls. Every one of the intrinsic controls are
available to every VB program you write.
When you create a "New" VB project, all 20 of
the intrinsic controls will show up in Toolbox.
This is true for all versions of VB.
UOG, IS Department Ins. G/M 16
17. The Most Useful Intrinsic Controls
These intrinsic controls are pretty much used on
every VB application. Start your learning with
these and then branch out.
each of the controls:
CommandButton
ImageBox
Option Button
CheckBox
PictureBox
TextBox
ListBox
Label
ComboListBox
UOG, IS Department Ins. G/M 17
18. 1.5. Working with Properties, Methods,
and Events
Properties
Objects are described with "properties" (data)
which tell you
what they look like, where they go, how they
will act, and what they contain.
Properties often describe physical properties
of the object (color or size), but they can also
describe behavior, and the data contained by
an object.
UOG, IS Department Ins. G/M 18
19. …
Examples of properties include:
Appearance___color
Behavior__dragging,visibility
Position___top,left.width,height
Content___text,graphics
Font__name,size,bold,italic
Value__data stored by the object
The following example shows the property list
for the "lastname" text box...
UOG, IS Department Ins. G/M 19
21. …
Methods
Objects usually have many things that they can
do or that can be done to them. These are
predefined procedures that often modify
properties of the object such as its location.
For example:
Move—change the location of an object
Drag–allow it to be dragged with by the mouse
Paint—display or redisplay the object
Draw (Point, Line)—use the object to draw (e.g.,
use a mouse) or draw with the object (e.g., a
picture object)
UOG, IS Department Ins. G/M 21
22. …
In the following example, the text1.move will
cause the text box to move and be resized
when the button is clicked
UOG, IS Department Ins. G/M 22
23. …
In many cases, values are passed to methods
that change property values.
For example, the "move" method in Visual
Basic is given values for the left and top
position as well as height and width. The
properties for left, top, width, and height are
changed by the "move" method.
UOG, IS Department Ins. G/M 23
24. …
Events
The secret to how most windows-based programs
lies in behaviors called "events". Events are
triggered when windows are "loaded," buttons
are "clicked," or text boxes are "changed." These
events drive the program. Objects can respond to
stimuli or things that are done to them. For
example: Click, Double Click, Mouse Down,
Over, Up, drag change
The following example from Visual Basic shows the
event list for the push button...
UOG, IS Department Ins. G/M 24
26. …
In many programming systems such as Visual
Basic and JavaScript, objects are associated
with behavior by appending a descriptive
behavioral term to the name of the object.
For example: "gobutton_click" indicating that
the button has been clicked. In some cases,
certain events such as "onclick" are explicitly
associated with the object, a button.
UOG, IS Department Ins. G/M 26
27. From a programming perspective, events are where the work is
done. Code is attached to events to drive a program. For
example:
Sub command1_click ()
Text1.text = "Hello World"
End Sub
In this example:
There are, at least, 2 objects (button and text box) and the
window.
The event is triggered when the user clicks the button,
Clicking the button (an event) triggers the command1_click
subroutine,
Which contains code for updating the text box.
Code written for events may be used to call other procedures,
change properties, or invoke methods.
UOG, IS Department Ins. G/M 27
28. 1.6.Working with Projects in event driven
Programming
Opening, saving and running VB projects
An existing project can be opened through the New project
window by selecting the project name listed under the
Existing or the Recent tab. Once the project is opened,
the form may not be visible; the desired form can be
opened using the Project window.
To save a new VB project for the first time, choose Save
Project As from the File menu. To save an updated
version of a previously saved project, click on the Save
Project from the File menu or Tool bar.
The VB project can be executed by clicking the Start Button
in the Tool bar or select Start from the Run menu. The
execution can be temporarily suspended by clicking on
the Break button or Break from Run menu.
UOG, IS Department Ins. G/M 28
29. 29
NB. Discus the following in group
Procedural vs. Event-Driven Programming
• Procedural programming is executed in
procedural order.
• In event-driven programming, code is executed
upon activation of events.
30. 30
“Hello World!”
of Event-Driven Programming
• The example displays a button in the frame. A
message is displayed on the console when a
button is clicked.
HandleEvent
Run