VB.NET Part2.ppt
VB.NET Part2.ppt
NET
J.V. Joshua
Type of Applications
• Types of Applications
• Console Application – Usually Text only application. Runs from a DOS or
COMMAND PROMPT screen.
• Windows Application – Graphical Interface user application. Typical
Windows application that you normally use, such as MS WORD etc.
• Web Based Windows Application – Web application that uses a Browser
such as Internet Explorer, Mozilla Firefox, chrome etc.
Type of Applications cont.
• Console application:
• Output is text based
• No graphics or forms
• Require little or no user interaction
• Can call window forms
• Lighter, less overhead than standard windows because of absence of graphics
• Good for login scripts, device drivers, backend processes, test programs etc
• Placed or control from command prompt window
Type of Applications cont.
When the above code is compiled and executed, it produces the following
result:
VB.NET CLASS!
VB.NET Sample cont.
• The first line of the program Imports System is used to include the
System namespace in the program.
• The next line has a Module declaration, the module Module1.
VB.Net is completely object oriented, so every program must contain
a module of a class that contains the data and procedures that your
program uses.
• Classes or Modules generally would contain more than one
procedure. Procedures contain the executable code, or in other
words, they define the behavior of the class. A procedure could be
any of the following: Function, Sub, Operator, Get, Set etc
VB.NET Sample cont.
• The next line( 'This program) will be ignored by the compiler and it
has been put to add additional comments in the program.
• The next line defines the Main procedure, which is the entry point for
all VB.Net programs. The Main procedure states what the module or
class will do when executed.
• The Main procedure specifies its behavior with the statement
• Console.WriteLine(“VB.NET CLASS")
• WriteLine is a method of the Console class defined in the System
namespace. This statement causes the message
• “VB.NET CLASS!" to be displayed on the screen.
VB.NET Sample cont.
• The last line Console.ReadKey() is for the VS.NET Users. This will
prevent the screen from running and closing quickly when the
program is launched from Visual Studio .NET.
Visual Basic Standard Modules
• A module is a global Visual Basic file that contains only code
– General purpose procedures, functions, and declarations of
variables and constants
– Can be accessed by all code in the same project
– No event handlers
– Stored in files that end with the .vb extension
– Appears in the Solution Explorer window along with entries
for the project’s form files
Visual Basic Standard Modules cont.
• The Module has the following characteristics:
• Modules
• contain a method named Sub Main() that can be used as the starting
point of the application. Note this applies to both Console Applications
and Windows Applications.
• contain variable declarations, functions & procedures or source code
ONLY! No forms!
• are a good place to put program code that may be common to several
forms or other modules.
• are like forms but without the visual!
• When you create a Console Application, Visual Basic automatically
creates a Module where you can begin entering your code:
Code Editor for Console
Application
• For a Console Application, the code editor is invoked immediately to
allow you to enter code in the Module.
• Simply begin entering code in the Module Document.
• The Code Editor screen contains two drop-down list boxes, one for
the Object you are coding and the other for the Methods & Event-
Procedures associated with the object:
Code Editor for Console
Application cont.
Main Screen for Windows
Application
Module Names and Module Files
• A module
– begins with a Module statement
– ends with an End Module statement
• Here is the general format:
• You can omit the Dim keyword if you specify Public, Protected,
Friend, Protected Friend, Private, Static, or Read Only.
• If you do not specify otherwise, variables you declare using a Dim
statement are Private. The following two statements are equivalent:
a)Arithmetic operators
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Floating Division
\ Integer (whole number) division
Mod Remainder division
^ Exponentiation (raising to a power)
& String concatenation (combination)
Operators cont.
• B)Relational operators
• Combine value(s) to returns Boolean value(true or false)
operator meaning
> Greater than
< Less than
= Equal to
<> Not equal to
>= Greater than or equal to
<= Less than or equal to
• All relational operator are binary
Operators cont.
• Logical operators
• combine multiple Boolean expressions into a compound Boolean expression
operator description
And combine two expression into one. Returns true if both expression are true
Or combine two expression into one. if both expression evaluate to false, Or returns
false, otherwise it returns true
Not negates an expression
Xor logically joins two expressions. If both expression evaluate to true or both
expression evaluate to false, Xor returns false; otherwise it returns true
Operators cont.
• Exercise:
• If n = 4, answer = “Y” Are the following expressions true or false?
1. Not (n < 6) = False
2. (answer = "Y") Or (answer = "y") = T
3. (answer = "Y") And (answer = "y") =f
4. Not (answer = "y") =T
5. (answer = “y”) Xor (answer = “y”) = T
Naming convention
• Naming convention
• The following standard naming convention are adopted
• The first three letter should be lowercase prefix indicating the control
type, e.g:
• lbl indicate label control
• txt indicate text control
• btn indicate button control
• The part of control name after the three letter prefix should describe the control
purpose
Naming convention cont.
• Below are lists of prefixes of the common data types
Data Type Prefix Sample Value
Boolean bln blnLoggedIn
Byte byt bytAge
Char chr chrQuantity
Date dte dteBirthday
Decimal dec decSalary
Double dbl dblCalculatedResult
Integer int intLoopCounter
Long lng lng CustomerID
Object obj objWord
Short sho shoTotalParts
string str strName