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/5Programming Concepts in C++ Rating: 0 out of 5 stars0 ratingsVisual Basic 6.0 Programming By Examples Rating: 5 out of 5 stars5/5AutoIT Scripting For Beginners Rating: 5 out of 5 stars5/5Integer Optimization and its Computation in Emergency Management Rating: 0 out of 5 stars0 ratingsModern Introduction to Object Oriented Programming for Prospective Developers Rating: 0 out of 5 stars0 ratingsLearn C++ Rating: 4 out of 5 stars4/5Microsoft Visual C++ Windows Applications by Example Rating: 4 out of 5 stars4/5Visual Basic .NET for complete beginners Rating: 5 out of 5 stars5/5AutoCAD Platform Customization: AutoLISP Rating: 0 out of 5 stars0 ratingsHello World: Student to Software Professional - a Transformation Guide 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 ratingsBoost.Asio C++ Network Programming Cookbook Rating: 0 out of 5 stars0 ratingsA Concise Guide to Object Orientated Programming Rating: 0 out of 5 stars0 ratingsIntroducing Bootstrap 4: Create Powerful Web Applications Using Bootstrap 4.5 Rating: 0 out of 5 stars0 ratingsStart-to-Finish Visual C# 2015 Rating: 5 out of 5 stars5/5Visual Studio Tips and Tricks: I Rating: 0 out of 5 stars0 ratingsEmbedded Computing: A VLIW Approach to Architecture, Compilers and Tools Rating: 0 out of 5 stars0 ratingsStart-to-Finish Visual Basic 2015 Rating: 5 out of 5 stars5/5Beginning Visual Basic 2015 Rating: 5 out of 5 stars5/5The Best Javascript Rating: 0 out of 5 stars0 ratingsJump Start Sass: Get Up to Speed With Sass in a Weekend Rating: 0 out of 5 stars0 ratingsLearn Professional Programming in .Net Using C#, Visual Basic, and Asp.Net Rating: 0 out of 5 stars0 ratingsData Structures and Algorithms Implementation through C: Let’s Learn and Apply Rating: 0 out of 5 stars0 ratingsWhat Is Sql ?: Fundamentals of Sql,T-Sql,Pl/Sql and Datawarehousing. Rating: 0 out of 5 stars0 ratingsProgramming ASP.NET Rating: 0 out of 5 stars0 ratingsRelational Database Systems Rating: 0 out of 5 stars0 ratings
Computers For You
Deep Search: How to Explore the Internet More Effectively 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/5Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5Network+ Study Guide & Practice Exams Rating: 4 out of 5 stars4/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsThe ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratings101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5AP Computer Science Principles Premium, 2024: 6 Practice Tests + Comprehensive Review + Online Practice Rating: 0 out of 5 stars0 ratingsCompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratingsChildhood Unplugged: Practical Advice to Get Kids Off Screens and Find Balance Rating: 0 out of 5 stars0 ratingsChatGPT Ultimate User Guide - How to Make Money Online Faster and More Precise Using AI Technology Rating: 0 out of 5 stars0 ratingsPractical Lock Picking: A Physical Penetration Tester's Training Guide Rating: 5 out of 5 stars5/5Elon Musk Rating: 4 out of 5 stars4/5Dark Aeon: Transhumanism and the War Against Humanity Rating: 5 out of 5 stars5/5The Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5Master Builder Roblox: The Essential Guide Rating: 4 out of 5 stars4/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 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