Professional Documents
Culture Documents
CSC301 - Chapter 2
CSC301 - Chapter 2
CSC301 - Chapter 2
Variables
TryParse method
Arithmetic expressions
ToString method
Named Constants
THE CONCEPT OF
EVENT-DRIVEN
PROGRAMMING
WHAT IS EVENT-DRIVEN?
Code is executed in response to events trigger by the user actions.
E.g.: Clicking the mouse, pressing a key on the keyboard, selecting an item
from a drop-down list, typing some words into textbox, etc.
Common events in VB 2017 are load, click, double-click, drag and
drop, pressing the keys and more.
Every form and every control placed on the form has a set of events
related to them.
To view the events, double-click the control (object) on the form to enter. the
code window.
THE LOAD The code appears on the left Click on the default event
side is the event procedure to view other events
EVENT associated with the load event. associated with the control
To start writing the code, click on any part of the form to go into the code window
as shown in Figure 2.1.
The event procedure is to load Form1 and it starts with the keywords Private Sub
and ends with End Sub.
This procedure includes the Form1 class and the event Load, and they are bind
together with an underscore, i.e. Form_Load.
It does nothing other than loading an empty form.
VARIABLES
WHAT IS VARIABLES?
Copy and store values entered by the user, so they may be manipulated
Perform arithmetic on values
Verify values to determine that they meet some requirements
Temporarily hold and manipulate the value of a control property
Remember information for later use in the program
DECLARING VARIABLES
Data entered by the user in a text box (numbers, letters and so on) is treated as a
string in Visual Basic.
Even when the Text property contains only numbers, it is still considered a string and
cannot be used as is in a calculation; instead, it must be converted to its numeric
equivalent.
One way of converting a string to a number is to use the TryParse method.
Every numeric data type in Visual Basic has a TryParse method that converts a string
to that particular data type.
TRYPARSE
METHOD (2
OF 3)
TRYPARSE METHOD
(3 OF 3)