Găsiți următorul dvs. carte preferat

Deveniți un membru astăzi și citiți gratuit pentru 30 zile
Vb Net Programming

Vb Net Programming

Citiți previzualizarea

Vb Net Programming

Lungime:
587 pages
2 hours
Editor:
Lansat:
Sep 22, 2014
ISBN:
9781312541399
Format:
Carte

Descriere

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.
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.
Editor:
Lansat:
Sep 22, 2014
ISBN:
9781312541399
Format:
Carte

Despre autor


Legat de Vb Net Programming

Cărți conex
Articole conexe

Previzualizare carte

Vb Net Programming - Martin Booch

Vb Net Programming

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

Ați ajuns la sfârșitul acestei previzualizări. Înscrieți-vă pentru a citi mai multe!
Pagina 1 din 1

Recenzii

Ce părere au oamenii despre Vb Net Programming

0
0 evaluări / 0 Recenzii
Ce părere aveți?
Evaluare: 0 din 5 stele

Recenziile cititorilor