operators , functions and options in vb.net
DESCRIPTION
VB.NETTRANSCRIPT
1
.NET
Operators, Functions ,Option
Shyam N. Chawda +91 7874391191
Shyam N. Chawda 2
Operators An operator is a symbol or other character
indicating an arithmetic operation that acts on one or more elements in an application.
That take one operand are called unary operators.
That take two operands are called binary operators.
Operators
Arithmetic ^, –, *, /, \, Mod, +
Assignment =, ^=, *=, /=, \=, +=, -=, &=
Comparison/Relational
=, <>, <, >, <=, >=, Like, Is
Concatenation &, +
Logical/bitwise Not, And, Or, Xor, AndAlso, OrElse
Miscellaneous operations
AddressOf, GetType
Shyam N. Chawda 4
Arithmetic\ is integer division./ is regular division.34 / 2.5 = 13.634 \ 2.5 = 17 (convert 2.5 into 2 then)^ exponent operator.2^4 = 16
Shyam N. Chawda 5
Assignment
=
Shyam N. Chawda 6
Comparison / Relational=Dim a, b As Integer a = 5 b = 10
If a = b Thenlogic…….
End If
Shyam N. Chawda 7
Comparison / Relational
If TypeOf btnIntDiv Is Button Then MsgBox("Hai") End If
Use the TypeOf...Is operator to determine whether a given object:
Is an instance of a given class
Shyam N. Chawda 8
Comparison / Relational
LikeDefined only for operands of type String.
The result is True if the first operand matches the pattern given in the second operand; False if not.
Shyam N. Chawda 9
Comparison / Relational
Dim ans As Booleanans = "F" Like "F" ans = "F" Like "f" ans = "F" Like "FFF" ans = "aBBBa" Like "a*a" ans = "F" Like "[A-Z]" ans = "F" Like "[!A-Z]" ans = "a2a" Like "a#a" ans = "aM5b" Like "a[L-P]#[!c-e]"
Shyam N. Chawda 10
Comparison / Relational
ans = "BAT123khg" Like "B?T*" ans = "CAT123khg" Like "B?T*"
Shyam N. Chawda 11
Logical /bitwise
AndAlso
Only And?AndAlso performs logical short-circuiting: if
the first operand of the expression is False, the second operand is not evaluated.
b = (93 > 67) AndAlso MyFunction()
Shyam N. Chawda 12
Logical /bitwiseOrElse
OR ?
OrElse performs logical short-circuiting: if the first operand of the expression is True, the second operand is not evaluated.
Shyam N. Chawda 13
Multiple statements in one line ( : )
x = 3 : y = 5 : z = 6
One statement in multiple lines ( _ )
name = "Mr." & " " & "Karna" & _ " " & "Bhavin" & " " & _ ", Trivedi"
Shyam N. Chawda 14
CommentComments are brief explanatory notes
added to code for the benefit of those reading it.
Comment ( )
Uncomment ( )
buttons on the Edit toolbar. REM:
Shyam N. Chawda 15
Option ExplicitUsed at file level to force explicit
declaration of all variables in that file.
On (Default)Enables Option Explicit checking.
Off Disables Option Explicit checking.
Default - Object type.
Shyam N. Chawda 16
Option ExplicitOption Explicit On
Dim MyVar As Integer
MyInt = 10
MyVar = 10
Shyam N. Chawda 17
Option StrictRestricts implicit data type conversions
OnGenerate an error
Off (Default)Compiler default is Option Strict Off if do not specify Option Strict in your code.
Shyam N. Chawda 18
Option Strict Dim MyVar As Integer
MyVar = 1000
'Attempting to convert to an Integer generates an error.
MyVar = 1234567890.9876542
MsgBox(MyVar)
Shyam N. Chawda 19
Object data typeDim objDb As Object
when you do not know at compile time what data type the variable might point to.
Can point to data of any data type,
Shyam N. Chawda 20
Object data typeWhatever data type it refers to, an Object
variable does not contain the data value itself, but rather a pointer to the value.
It always uses four bytes in computer memory, but this does not include the storage for the data representing the value of the variable.
Shyam N. Chawda 21
Object data typeThe Object data type is slower than using
explicit data types.
The code that uses the pointer to locate the data, Object variables holding value types are slightly slower to access than explicitly typed variables.
Shyam N. Chawda 22
IMP functions , constants
vbCrLf Carriage return/linefeed character combination.
vbNewLine Newline character. vbTab Tab character.
Shyam N. Chawda 23
IMP functions , constants
Space(Integer)
InputBox()
MsgBox()
MessageBox.Show()
Val()
Shyam N. Chawda 24
With…End Withwhen we want to set number of properties
and methods related with one control or object that time use with..end with block.
It executes series of statement related to one control or object
Shyam N. Chawda 25
With…End WithSyntax:
With objname
end With
Shyam N. Chawda 26
With…End With
Shyam N. Chawda 27
With…End WithWith MyLabel .Height = 200 .Width = 200 .Text = "Demo Label"End With
28
Thanks
Any questions?www.shyamsir.com
Shyam N. Chawda