CSC 215 Summary
CSC 215 Summary
Introduction
This document compiles information from several sources related to VB.Net programming. It covers fundamental concepts such as data types,
control structures, procedures (functions and subs), object-oriented programming, error handling and more. It serves as a summary of the
material.
I. Fundamental Concepts
Imperative Statements and Subroutines:An "Imparative statement" is a command that tells the computer to execute an action irrespective
of any existing conditions.
A "Sub routine" is a packaged sequence of programmed instructions that performs a specific task. It can be called a procedure, function,
routine, or subprogram. Subroutines are often "Coded" so they can be reused from several places without modification.
A "block" is a "lexical structure of source code or connection of instructions grouped together."
Data Types: VB.Net has numeric and non-numeric data types.
"Numeric data type consist of numbers that can be calculated mathematically using varying standard operations." Examples include exam
marks, length, height, school fees, and population.
Numeric types include "integer, bigoit, decimal, number, population, money, and date data type."
"Floating point numbers are numbers without a fixed number of digits before and after the decimal point."
Non-numeric data types include:
String: Can be fixed or variable length. Fixed length strings range from "1 to 65,400 characters", while variable length strings range from "0 to
2 billion characters".
Date: Stores dates, with a range from "January 1, 100 to December 31, 9999."
Boolean: Represents true/false values, coded as "0 and 1" or "True".
Object: Can store any embedded object.
Currency: "8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807"
Decimal "12 bytes +/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use +/- 7.9228162514264337593543950335 (28 decimal
places)."
Literals: "are values attached to data; a notation for representing a fixed value in source code."
String literals are enclosed in "“ ”", while date and time literals are enclosed in "# #".
String Manipulation: VB.Net provides functions for manipulating strings.
LEN("lagos state") + 15 = 26 (Length of string + 15)
Right("lagos state", 3) = "ate" (Extract rightmost 3 characters)
Left("lagos state", 3) = "lag" (Extract leftmost 3 characters)
Mid("lagos state",3, 3) = "gos" (Extract 3 characters starting from position 3)
Boolean Values: Boolean variables can be coded as "0 and 1 true"
Looping: This is a "process of executing a set of instruction repeatedly" with a "collection of instruction executed repeatedly" known as a
loop.
For...Next Loops: Used to repeat a block of code a specified number of times. Examples are provided demonstrating increasing (For
counter=1 to 10...), incrementing by a step (For counter=1 to 100 step 10...), and decrementing (For counter = 100 To 5 Step -5...). Can be
exited early using Exit For when used with an If condition.
Do...Loop: Executes a block of code while or until a certain condition is met. Variations include Do While...Loop, Do...Loop While, Do
Until...Loop, and Do...Loop Until. Can be exited early using Exit Do.
Conditional Statements:If...Then...ElseIf...Else...End If: Allows for executing different actions based on different conditions. Code is
executed based on the first true condition. An else statement executes if no previous condition is met.
Variable Declaration:Variables are declared using the Dim statement, as in Dim counter as Integer or with Private, Static, or Public keywords.
Private creates a variable local to a procedure or module; Static variables retain their values even after a procedure is terminated. Public
declares a variable available to the whole project.
The Dim statement is used for "variable declaration and storage allocation for one or more variables" and can be used at module, class,
structure, procedure or block level.
Syntax is [ < attributelist > ] [ accessmodifier ] [[ Shared ] [ Shadows ] | [ Static ]] [ ReadOnly ] Dim [ WithEvents ] variablelist where the
attributes and access modifiers are optional.
Variable Scope: Private is rarely used, with Dim being used to declare a local variable, and the Static keyword makes a variable used multiple
times, even after a procedure has ended.
Variable Naming: Variable names "must begin with a letter that could be followed by a sequence of letters, digits (0 - 9) or underscore." It
"must not contain any embedded space or symbol" and "should not be a reserved keyword".
Lvalues and Rvalues: Lvalues can appear on both sides of an assignment, and are typically variables. Rvalues, typically numeric literals, can
only appear on the right side of an assignment.
Constants: "refer to fixed values that the program may not alter during its execution." Can be any basic data type.
Enumerations: "An enumerated type is declared using the Enum statement" and can be used at any scope.
Functions:"Functions return a value" and can use the Return statement or assign the value to the function name.
Functions can be declared as Public (applicable to the whole project) or Private (applicable to a certain module or procedure), as in Public
Function functionName (Argument As dataType,……….) As dataType.
Arguments can be passed ByVal (by value) or ByRef (by reference). When passed by ByVal, the original variable is not modified by the
procedure, but when passed by ByRef, the original variable is modified. If neither is stated, the default is ByRef.
Sub Procedures: Subs are declared with the Sub keyword, e.g., Sub mySub(ByVal s As String) ... End Sub They perform tasks, but unlike
functions, they do not directly return values.
Recursive Functions: Functions can call themselves; this is "known as recursion".
Param Arrays: Allow a variable number of arguments to be passed to a function.
V. Operators
Types of Operators: VB.Net supports arithmetic, comparison, logical/bitwise, bit shift, and assignment operators.
Arithmetic Operators: Include ^ (exponentiation), + (addition), - (subtraction), * (multiplication), / (division with floating-point result), \
(integer division), Mod (modulus).
Comparison Operators: Include =, <>, >, <, >=, <=. Also, the operators Is, IsNot and Like are used for specific comparisons.
Logical/Bitwise Operators: Include And, Or, Not, and Xor. Bitwise operators perform operations on individual bits.
Bit Shift Operators: << (left shift) and >> (right shift)
Assignment Operators: Include =, +=, -=, *=, /=, \=, ^=, <<=, >>=, &=.
Miscellaneous Operators: Include AddressOf, Function Expression, and If
Operator Precedence: Determines the order in which operators are evaluated in an expression. Examples include, exponentiation first,
division next and additions and subtraction last etc.
Classes and Objects:A "class" is a blueprint for creating objects; objects are "instances of a class". Classes consist of members such as
member functions and member variables.
Classes are defined using the keyword Class.
Member variables (attributes of an object) are typically kept private (encapsulated) and accessed using public member functions.
Shared Members: Shared member variables and functions are associated with the class itself rather than an instance of the class.
Inheritance: Classes can be derived from base classes, inheriting properties and methods.
The syntax used for creating derived classes is <access-specifier> Class <base_class> ... End Class Class <derived_class>: Inherits
<base_class> ... End Class
Modifiers: Modifiers are keywords that give "some especial emphasis on how the programming element will behave or will be accessed in
the program" such as, Public, Private and Protected.
File Handling: VB.Net uses classes from the System.IO namespace for file operations. This includes classes like FileStream, StreamReader,
and StreamWriter.
File Mode Enumerators: Can be used to define Open, OpenOrCreate, and Truncate
File Access Enumerators: Can be used to define Read, ReadWrite, and Write.
FileShare Enumerators: Can be used to define file sharing settings such as Inheritable, None, Read, ReadWrite, and Write.
DirectoryInfo, DriveInfo, File, FileInfo, MemoryStream, Path, StreamReader, and StringReader are all classes that form part of the System.IO
namespace.
Compiler Directives: These begin with # and include #Const, #ExternalSource, #If...Then...#Else, and #Region. They are used to help in
conditional compilation and do not perform macro creation as in C++.
Date & Time: VB.Net provides tools for date and time arithmetic. Dates are usually enclosed in hash signs (# #) and formatted in M/d/yyyy
format. Predefined date/time formats are supported including "d", "D", "t", "T", "f", "F", "g", "G", "M", "R", and "y" formats.
Arrays: Used to store collections of items. Dynamic arrays can be re-dimensioned with ReDim, e.g. ReDim [Preserve]
arrayname(subscripts)Multi-dimensional arrays and jagged arrays are also supported, e.g. Dim twoDarray(10, 20) As Integer, and Dim scores
As Integer()() = New Integer(5)(){} respectively.
Bit Arrays: Allow for dynamic storage of bit values.
IDE: Visual Web Developer, Visual Basic Express (VBE) and Visual Studio (VS) are all IDE development tools provided by Microsoft for
VB.Net.
Assembly Language: Is a programming language that uses 0's and 1's.
X. Key Definitions
XI. Compatibility
VB.Net is not compatible with VB6.