Vb Net Programming
By Martin Booch
()
About this ebook
KEY FEATURES
VB.Net Programming without requiring previous experience in another language
Simple language has been adopted to make the topics easy and clear to the readers
Topics have been covered with numerous examples in VB.NET and ADO.NET.
Most of the programs are executed and presented with Screen display so as to enable the readers to learn the logic of programming
Provides exercises, review questions and programming exercises at the end of each chapter.
Related to Vb Net Programming
Related ebooks
Visual Basic 2010 Coding Briefs Data Access Rating: 5 out of 5 stars5/5I am Linux : Being A Ultra Linux User Rating: 0 out of 5 stars0 ratingsMastering PyCharm Rating: 5 out of 5 stars5/5Debian 8 for Beginners Rating: 3 out of 5 stars3/5Professional Access 2013 Programming Rating: 0 out of 5 stars0 ratingsVisual Basic .NET for complete beginners Rating: 5 out of 5 stars5/5Learn Professional Programming in .Net Using C#, Visual Basic, and Asp.Net Rating: 0 out of 5 stars0 ratingsIvor Horton's Beginning Visual C++ 2013 Rating: 0 out of 5 stars0 ratingsBackup and Restore The Ultimate Step-By-Step Guide Rating: 0 out of 5 stars0 ratingsEmbedded: Confessions of a TV Sex Journalist Rating: 0 out of 5 stars0 ratingsVisual Studio 2022 In-Depth: Explore the Fantastic Features of Visual Studio 2022 - 2nd Edition Rating: 0 out of 5 stars0 ratingsC++ Game Development Cookbook: C++ Game Development Cookbook Rating: 0 out of 5 stars0 ratingsC Programming Wizardry: From Zero to Hero in 10 Days: Programming Prodigy: From Novice to Virtuoso in 10 Days Rating: 0 out of 5 stars0 ratingsObjective-C Programming Nuts and bolts Rating: 0 out of 5 stars0 ratingsAdvanced C++ Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsC# Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratings"C Programming for Beginners: A Step-by-Step Guide" Rating: 0 out of 5 stars0 ratingsMCS-011: Problem Solving and Programming Rating: 0 out of 5 stars0 ratingsProgramming with Python Rating: 0 out of 5 stars0 ratingsJavascript - 50 functions and tutorial Rating: 0 out of 5 stars0 ratingsBE EXPERT IN JAVA Part- 2: Learn Java programming and become expert Rating: 0 out of 5 stars0 ratingsSchaum's Easy Outline: Programming with C++ Rating: 4 out of 5 stars4/5C Programmin Language Rating: 0 out of 5 stars0 ratingsPython Programming Using Google Colab Rating: 0 out of 5 stars0 ratingsGd Script Rating: 0 out of 5 stars0 ratingsCoding In C Decoded: Decoded, #1 Rating: 0 out of 5 stars0 ratingsJavaScript Interview Questions You'll Most Likely Be Asked Rating: 0 out of 5 stars0 ratingsSoftware Design Simplified Rating: 0 out of 5 stars0 ratingsC++ Programming Language Rating: 0 out of 5 stars0 ratingsUnleashing the Power of TypeScript Rating: 0 out of 5 stars0 ratings
Computers For You
Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Data Analytics for Beginners: Introduction to Data Analytics Rating: 4 out of 5 stars4/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5Algorithms to Live By: The Computer Science of Human Decisions Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5The Alignment Problem: How Can Machines Learn Human Values? Rating: 4 out of 5 stars4/5Storytelling with Data: Let's Practice! Rating: 4 out of 5 stars4/5Narrative Design for Indies: Getting Started Rating: 4 out of 5 stars4/5Python for Finance Cookbook: Over 50 recipes for applying modern Python libraries to financial data analysis Rating: 0 out of 5 stars0 ratingsGet Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5Python for Beginners: A Crash Course to Learn Python Programming in 1 Week Rating: 0 out of 5 stars0 ratingsHow Do I Do That In InDesign? Rating: 5 out of 5 stars5/5The Unaccountability Machine: Why Big Systems Make Terrible Decisions - and How The World Lost its Mind Rating: 0 out of 5 stars0 ratingsPython Machine Learning By Example Rating: 4 out of 5 stars4/5ITIL® 4 Essentials: Your essential guide for the ITIL 4 Foundation exam and beyond, second edition Rating: 5 out of 5 stars5/5Black Holes: The Key to Understanding the Universe Rating: 5 out of 5 stars5/5Advances in Financial Machine Learning Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn Algorithmic Trading: Build and deploy algorithmic trading systems and strategies using Python and advanced data analysis Rating: 0 out of 5 stars0 ratingsDeep Learning with PyTorch Rating: 5 out of 5 stars5/5Django Building Dynamic Website With Django : A Complete Step By Step Guide To Learn to Build Modern Web Application with a Python Rating: 0 out of 5 stars0 ratingsArtificial Intelligence: The Complete Beginner’s Guide to the Future of A.I. Rating: 4 out of 5 stars4/5Learn SAP MM in 24 Hours Rating: 0 out of 5 stars0 ratingsThe ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 4 out of 5 stars4/5
Reviews for Vb Net Programming
0 ratings0 reviews
Book preview
Vb Net Programming - Martin Booch
Vb Net Programming
By Martin Booch
Publisher Lulu.com
ISBN: 978-1-312-54139-9
Overview:
VB.Net Programming: This book is specially written for the students of Computer engineering and Information Technology
VB.Net Programming teaches the application development concepts from the scratch using Microsoft .Net Framework Technology in an easy-to-follow style, without assuming previous experience in any other language. This book starts with developing windows application using VB.NET. A variety of examples make learning these Concepts with VB.NET both fun and practical. This book is organized in such a manner that students and programmers can find it easy, crisp and readable. Each Chapter contains many example programs within the book, along with additional examples for further practice.
KEY FEATURES
Step-Wise approach throughout the book
VB.Net Programming without requiring previous experience in another language
Simple language has been adopted to make the topics easy and clear to the readers
Topics have been covered with numerous examples in VB.NET and ADO.NET.
Most of the programs are executed and presented with Screen display so as to enable the readers to learn the logic of programming
Provides exercises, review questions and programming exercises at the end of each chapter.
Copyright
VB.Net Programming
Copyright © 2014 Reserved by Gayatri Patel
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is
basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
1.5Variables
A variable is a data name that may be used to store a data value. A variable may take different value at different times during execution. As variable is an identifier, all the rules for naming an identifier applies to variables also.
Rules for Variable Naming
First character must be an alphabet or underscore.
Must consist of only letters, digits, or underscore.
Only first 1023 characters are significant.
Cannot use a keyword.
Must not contain white space.
Variable Declaration
Syntax,
Modifier Dim Variablename as Datatype
Here, Modifier can be Public, Protected, Friend, Protected Friend, Private or Static. Dim (which originally stood for dimension, as when you set the dimensions of an array) is the required keyword. Variablename is the name of variable.
Example,
Dim a As Integer
Dim b As Double
Dim c As Char
Dim d As String
Multiple variables with same datatype can be declared in single line.
Example,
Dim a, e As Integer
Multiple variables with different datatypes also can be declared in single line.
Example,
Dim a, e As Integer, b As Double, c As Char, d As String
Variable Initialization
Variable can be initialized at a time of declaration or after declaration.
Example,
Initialization at a time of Declaration
Dim a As Integer = 10
Dim b As Double = 23.78
Dim c As Char = v
Dim d As String = Hello
Initialization after Declaration
Dim a As Integer
a = 10
Dim b As Double
Dim c As Char
b = 23.78
c = v
Dim d As String
d = Hello
1.6Constant
Constant is a variable, refers to a fix value that do not change during the execution of program.
Syntax,
Const variablename as datatype = value
Example,
Const pi As Double = 3.1416
Const a As String = A
Const temp As Integer = -1
Here, the value of variables pi, a and temp will never change during the execution.
Type Conversion
If any expression involves two different types of operands, then to evaluate expression properly, both operands are converted into same type. Such conversion is called Type Conversion. There are two ways of Type Conversion:
Implicit Type Conversion
Explicit Type Conversion (Type casting)
Implicit Type Conversion
Whenever as expression involves two different types of operands, VB.Net automatically converts any intermediate values to the proper type so that the expression can be evaluated without losing any significance. This automatic conversion is known as Implicit Type Conversion. If the operands are of different types, then the operand with a lower type is upgraded to the higher type and then the operation is performed.
Implicit Type Conversion can be classified as Widening Conversion and Narrowing Conversion. When the value of operand with lower type is assigned to the operand with higher type then there is not any loss of accuracy, and this conversion is called Widening Conversion. When the value of operand with higher type is assigned to the operand with lower type then there may be loss of accuracy (resultant value may not be accurate), and this conversion is called Narrowing Conversion. When Option Strict is On, Narrowing Conversion cannot be done. Narrowing Conversion can be done only when Option Strict is Off.
Example
Imports System.Console
Module Module1
Public Sub Main()
Dim a As Integer = 3
Dim b As Integer
Dim c As Double = 5.5
b = a + c
WriteLine(b = {0}
, b)
c = a
WriteLine(c = {0}
, c)
ReadKey()
End Sub
End Module
Output:
b = 8
c = 3
Here, the operand a is of type Integer and c is of type Double. a will be upgraded to type Double and a + c will be evaluated to 8.5 and assigned to b, which is of type Integer, so truncated value of 8.5 will be the value of b. So, 8 will be assigned to b. Here, operand with higher type (Double) is assigned to the operand with lower type (Integer), which is called Narrowing Conversion. In next statement a is assigned to c, means operand with lower type (Integer) is assigned to the operand with higher type (Double), which is called Widening Conversion.
Explicit Type Conversion (Type Casting)
Type casting is explicitly specified by the programmer in the program. There are following methods used for Explicit Type Conversion:
Example
Imports System.Console
Module Module1
Public Sub Main()
WriteLine(CBool(
1
) : {0}
, CBool(1
))
WriteLine(CSByte(
123
) : {0}
, CSByte(123
))
WriteLine(CByte(
34
) : {0}
, CByte(34
))
WriteLine(CChar(
a
) : {0}
, CChar(a
))
WriteLine(CDate(
1/1/2012
) : {0}
, CDate(1/1/2012
))
WriteLine(CShort(
14
) : {0}
, CShort(14
))
WriteLine(CUShort(
2341
) : {0}
, CUShort(2341
))
WriteLine(CInt(
145
) : {0}
, CInt(145
))
WriteLine(CUInt(
11234
) : {0}
, CUInt(11234
))
WriteLine(CLng(
1.23
) : {0}
, CLng(1.23
))
WriteLine(CULng(
1.56545
) : {0}
, CULng(1.56545
))
WriteLine(CSng(
1.342
) : {0}
, CSng(1.342
))
WriteLine(CDbl(
1.12323
) : {0}
, CDbl(1.12323
))
WriteLine(CDec(
1123
) : {0}
, CDec(1123
))
WriteLine(CObj(
aadsd
) : {0}
, CObj(aadsd
))
WriteLine(CStr(12) : {0}
, CStr(12))
ReadKey()
End Sub
End Module
Output:
CBool(1
) : True
CSByte(123
) : 123
CByte(34
) : 34
CChar(a
) : a
CDate(1/1/2012
) : 1/1/2012
CShort(14
) : 14
CUShort(2341
) : 2341
CInt(145
) : 145
CUInt(11234
) : 11234
CLng(1.23
) : 1
CULng(1.56545
) : 2
CSng(1.342
) : 1.342
CDbl(1.12323
) : 1.12323
CDec(1123
) : 1123
CObj(aadsd
) : aadsd
CStr(12) : 12
Scope of Variables
The scope of a variable, sometimes referred to as accessibility of a variable, refers to where the variable can be read from and/or written to. The lifetime of variable, referred to how long variable stays in memory. There are many different ways you can declare variables. How you make these declarations controls the scope of variables.
Block Level Scope
If a variable declared within a block (If Statement or Loop), that variable's scope is only until the end of the block. The lifetime is until the block ends.
Example
Imports System.Console
Module Module1
Sub Main()
If True Then
Dim b As Integer = 10
WriteLine(b)
End If
ReadKey()
End Sub
End Module
Output:
10
Here, the variable b is declared in If statement. So the scope of variable is until the end of If statement.
Procedure Level Scope
If a variable declared within a procedure, but outside of any (If Statement or Loop), the scope is until the end of procedure (End Sub or End Function). The lifetime of the variable is until the procedures ends.
Example
Imports System.Console
Module Module1
Sub Main()
Dim a As Boolean = True
If a = True Then
Dim b As Integer = 10
WriteLine(b)
End If
ReadKey()
End Sub
End Module
Output:
10
Here, the variable a is declared in Sub procedure Main(). So the scope of variable is until the end of Main(), means upto End Sub.
Module Level Scope
A variable can be declared outside of any procedure, but it must be within a Class....…End Class or Module....…End Module statement. The scope is any procedure within this module (until the end of the module). The lifetime for a variable defined within a class is until the object is cleaned up by the garbage collector. The lifetime for a variable defined within a module is until the program ends.
Example
Imports System.Console
Module Module1
Dim a As Integer = 10
Sub Main()
WriteLine(a)
ReadKey()
End Sub
End Module
Output:
10
Here, the variable a is declared in Module1, but outside Sub procedure Main(). So the scope of variable is until the end of Moduel1, means variable a can be accessed in any procedure within Module1.
Global Level Scope
A Public variable can be declared within a Module…....End Module statement, and that variable's scope will be any procedure or method within the project. The lifetime of the variable will be until the program ends.
Example
Imports System.Console
Module Module1
Public a As Integer = 10
Sub Main()
WriteLine(a)
ReadKey()
End Sub
End Module
Output:
10
Here, the variable a is declared as Public and in Module1. So the scope of variable is throughout Application, means variable a can be accessed in any module within same Application.
Methods used in VB.Net
Methods used to Identify Variable Type
GetType() and GetTypeCode(). GetType() returns Variable DataType as string value. GetTypeCode() returns Variable DataType Code as integer value. Every DataType has any unique identification Code that is an integer number.
Example,
Dim b As Boolean
Dim c As Char
Dim d As Date
Dim i As Integer
Dim u As Ulong
Dim s As String =
Validation Methods
Example,
Dim a As Integer = 12.67
Dim b As String = 3
Dim c As String = a23
Dim d As Object
Dim e As Date = 1/1/2012
Dim f As String = 1/1/2012
1.7Operators and Expressions
VB.Net provides the following types of Operators:
1.7.1Arithmetic Operators
Arithmetic Operators are used to perform familiar calculations on numeric values, including shifting their bit patterns. Arithmetic operators are:
Example,
Dim a As Integer = 10
Dim x As Double = 5, y As Double = 3
Dim s As String = Hello
1.7.2Comparison Operators
Comparison Operators are used to compare two expressions and return a Boolean value representing the result of the comparison. Comparison operators are:
Example,
Dim a As Integer = 10, b As Integer = 2
Dim s As String = Hello
Dim x As New DataTable
x = Nothing
Dim y As New DataTable
y = Nothing
1.7.3Concatenation Operators
Concatenation Operators are used to join multiple