Tuesday, August 31, 2010

Visual Basic Math Function : C < type > Numeric Conversion

Visual Basic Math Function : Hex

Purpose : The Hex function converts a decimal numeric expression to a variant or string that represents the value of the numeric expression in expression in hexadecimal format.

Syantax :
Hex ( numExpression )

numExpression : Numeric expression to be conerted to hexadecimal notation.

A% = 140
B$ = Hex ( A% )

This example places a string with thehexadecimal value "8C" into the variable B$.

Visual Basic Math Function : Oct

Purpose : The Oct function returns a variant or string that represents the supplied numeric expression in octal notation (base8)

Syntax :
Oct ( numExpression )

numExpression : Numeric expression to be converted to octal notation.

strOctal = Oct ( 100 )

Visual Basic Math Function : Str

Purpose : the Str function converts a numeric expression to a string .

Syntax :
Str ( numExpression )

numExpression : Numeric expression you want to convert to a string .

A$ = Str ( 100 )
B$ = Str ( -100 )

The value of A$ becomes "100" and B$ "-100". string value return .

Visual Basic Math Function : Val

Purpose : The Val function returns the numeric value of the supplied string expression.

Syntax :
Val ( strExpression )

strExpression : String for which you want to return the numeric value

A! = Val ( "123" )
B! = Val ( "1 2 3" )
C! = Val ( "123Sam" )
D! = Val ( "A" )

First Three example line assign a value of 123 to their respective variables but fourth line return 0

Visual Basic Math Function : Tan

Purpose : The Tan function returns the tangent of an angle.

Syntax :
Tan ( dblAngle )

dblAngle : Numeric expression for which you want to return the tangent

Dim dblResult as Double
dblResult = Tan (4.93 )

Visual Basic Math Function : Sqr

Purpose : The Sqr function returns the square root of a number.

Syntax :
Sqr ( dblExpression )

dblExpression : Numeric expression of which you want to return the square root

Dim dblResult as Double
dblResult = Sqr ( 72 )

This example places the square root of 72 into the variable into the variable dblResult. giving it a value of 8.485281

Visual Basic Math Function : Sin

Purpose : The Sin function returns the sine of an angle

Syntax :
Sin ( dblAngle )

dblAngle : Numeric expression for which you want to return the sine.

Dim dblResult as Double
dblResult = Sin ( 4.93 )

The sine of 4.93 is assigned to the variable dblResult. Sin is used to determine the sine of an angle. The function expects the angle to be expressed in radians; therefore, if the angle is in degrees, it must be converted by using the formula.

Radians = Degrees X pi / 180

Visual Basic Math Function : Sgn

Purpose : The Sgn function evaluates a numExpression and returns a value based on whether the numExpression is negative, positive , or 0.

Syntax :
Sgn ( numExpression )

numExpression : Numeric expression for which you want to determine the sign.

intSign1 = Sgn ( 100 )

This example sets the variable intSign1 to 1 , indicating that the numExpression evaluated was positive.

intSign2 = Sgn ( 0 )

This example sets the variable intSign2 to 0 , indicating that the numExpression evaluated was 0.

intSign3 = Sgn ( -100 )

This example sets the variable intSign3 to -1 , indicating that the numExpression evaluated was negative.

Visual Basic Math Function : Rnd

Purpose : The Rnd function returns a single-precision random number between 0 and 1 .

Syntax :
Rnd [ ( lngExpression ) ]

lngExpression : A value that determines which number in the pseudo-random sequence to return ( optional )

Function RndInt ( intLoNum as Integer , intHiNum as Integer ) as Integer
Static blnSeeded as Boolean
Dim intRange as Integer
if blnSeeded = False Then
Randomize
blnSeeded = True
Enf if
intRange = intHiNum - intLoNum + 1
RndInt = Int ( intRange * Rnd + intLoNum )
End Function

This example is a function that uses the Randomize statement and Rnd function to return an integer in the range specified by the integer parameters intLoNum and intHiNum.

Visual Basic Math Statement : Randomize

Purpose : The Randomize statement seeds the random number generator, allowing the generation of a new sequence of random numbers.

Syntax :
Randomize [ lngSeed ]

lngSeed : Seed number for a sequence of pseudo random numbers ( optional )

Function RndInt ( intLoNum as Integer , intHiNum as Integer ) as Integer
Static blnSeeded as Boolean
Dim intRange as Integer
if blnSeeded = False Then
Randomize
blnSeeded = True
Enf if
intRange = intHiNum - intLoNum + 1
RndInt = Int ( intRange * Rnd + intLoNum )
End Function

This example is a function that uses the Randomize statement and Rnd function to return an integer in the range specified by the integer parameters intLoNum and intHiNum.

Monday, August 30, 2010

Visual Basic Math Function : Log

Purpose : The Log function returns the natural logarithm of a numeric expression. the natural logarithm, which has a base of approximately 2.718282.

Syntax :
Log ( dblExpression )

dblExpression : Numeric expression for which you want to return the natural logarithm

Dim dblNumber , dblResult as Double
dblNumber = 14
dblResult = Log ( dblNumber )

This example returns a double precision number that represents the natural logarithm for 14.

Visual Basic Math Function : Int

Purpose : The Int function returns the largest integer that is less than or equal to then supplied numeric expression.

Syntax :
Int (numExpression )

numExpression : Numeric expression for which you want to return the largest integer less than or equal to it.

A% = Int ( -2.86 )
B% = Int ( 2.86 )

These statements place the value -3 in the variable A% and then value 2 in the variable B%

Value Int ( value )
2.7 2
2.2 2
2 2
-2 -2
-2.2 -2
-2.8 -.3

Visual Basic Math Function : Fix

Purpose : The Fix function truncates the fractional part of a numeric expression and returns the rest as an integer.

Syntax :
Fix ( dblExpression )

dblExpression : Numeric expression of which you want to return the value with the fractional part truncated

Dim dblNumber as Double
Dim intResult as Integer
dblNumber = 54.72
intResult = Fix ( dblNumber )

intResult have value is 54

Value Fix ( Value )
2.7 2
2.2 2
2 2
-2 -2
-2.2 -2
-2.7 -2

Visual Basic Math Function : Exp

Purpose : The Exp function raises the natural logarithmic base to the specified power. ( the natural logarithm, which has a base of about 2.718282 should not be confused with the common logarithm, whose base is 10.)

Syntax :
Exp ( dblPower )

dblPower : Numeric expression repression representing the power to which you want to raise the number e.

Dim dblNumber as Double, dblResult as Double
dblNumber = 14
dblResult = Exp ( dblNumber )

This example returns a double-precision number that represents the natural logarithmic base raised to the power of 14.

Wednesday, August 18, 2010

Visual Basic Math Function : Cos

Purpose : Return the cosine of a numeric expression.

Syntax :
Cos ( dblAngle )

dblAngle : Numeric expression for which you want to return the cosine

A! = Cos ( 4.93 )

The Cos function determines the cosine of an angle. the function expects the angle to be expressed in radians ; if the angle is in degrees, ti must first be converted using the formula

Radians = Degrees X pi/180

If the angle is supplied as an integer of a single-precision value. Cos returns a single-precision value ; otherwise, it returns a double-precision value.

Visual Basic has four trigonometric function: Tan, Atn, Sin, Cos

Visual Basic Math Function : Atn

Purpose : Return the arctangent of a numeric expression.

Syntax :
Atn ( dblExpression )

dblExpression : Numeric expression for which you want to return the arctangent

Dim dblAngle as Double, dblRatio as Double
dblAngle = Atn ( dblRatio )

Atn is a Trigonometric Function. The arctangent is the inverse of tangent. The arctangent of a number gives the size of the angle for which the number is the tangent.

Visual Basic Math Function : Abs

Purpose : Return the absolute value of a numeric expression.

Syntax :
Abs ( numExpression )

numExpression : Numeric expression of which you want to return the absolute value

aNumber = Abs ( aSignedNumber )

Abs returns the unsigned value of the supplied numeric expression. Abs ( -299 ) then return value is 299.

Tuesday, August 17, 2010

Visual Basic String Function : FormatCurrency

Purpose : FormatCurrency is a subset feature of the Format function, which returns a mumber formatted as a currency value using the currency symbol - such as a leading dollar sign, commas separating millions and thousands and so on.

Syntax
FormatCurrency ( expression [ , NumdigitsAfterDecimal [ , IncludeLeadingDigit [ , UseParensForNegativeNumbers [ , GroupDigits ] ] ] ] )

Visual Basic String Function : WeekdayName

Purpose : WeekdayName returns the name of the day of the week based on the number passed.

Syntax :
WeekdayName ( weekday , [ abbreviate] , [ firstdayofweek ] )

weekday : Numeric value for the day of the week
abbreviate : Boolean value that indicates whether the weekday name should be abbreviated.
firstdayofweek : Numeric value indicating the first day of the week.
vbUseSystem = Uses National Language support (NLS) API
vbSunday
vbMonday
vbTuesday
vbWednesday
vbThursday
vbFriday
vbSaturday

retStr = WeekdayName (3 )

The WeekdayName function returns the day of the week of the passed numeric argument . The value returned in the sample syntax is "Tuesday".

Visual Basic String Function : UCase

Purpose : The UCase function returns a copy of a a string in which all lowercase alphabetic characters have been converted to uppercase.

Syntax :
UCase ( strExpression )

strExpression : String you want conerted to uppercase

Dim strCommand as String
Dim strUpperCommand as String
strCommand = Command
StrUpperCommand = UCase ( strCommand )

Visual Basic String Function : Trim

Purpose : Trim removes leading and trailing spaces from a string or byte array.

Syntax :
Trim ( string )

string : The string being trimmed

ds!Name = Trim ( txtName.text )

Trim serves as combination of the LTrim and RTrim function; it removes all spaces from a string or byte array. Trim generally is used with data entered on a form to make sure no extraneous spaces are stored with the data.

Visual Basic String Function : String

Purpose : The String function returns a string containing the specified number of the requested character.

Syntax :
String ( lngNumChars, intANSICode )
String ( lngNumChars, strCharacters)

lngNumChars : Number of repeating characters in the returned string
intANSICode : ANSI code of the character to ve repeated in the returned string
strCharacters : String where the first character is the character to be repeated in the returned string

Dim strString as String
strString = String ( 10 , " * " )
strString = String ( 10 , 42 )

Because 42 is the ANSI code for asterisk character , both of these statements return the same value : "**********"

Visual Basic String Function : StrReverse

Purpose : The StrReverse function returns a string that has all its characters n reverse order.

Syntax :
retStr = StrReverse ( String1 )

String1 = Specities the string that should have all its characters displayed in reverse

retStr ( StrReverse ( " Join Samrudhi Computers for be a Computer Programmer " )

Result is " remmargorP retupmoC a eb rof sretupmoC ihdurmaS "
You had to write our own function to do this using the Mid$ function and iterate through the string using a For....Next..Loop . Now that it is a built -in function, this process is a lot faster than any function that could be written in Visual Basic.

Monday, August 16, 2010

Visual Basic String Function : StrConv

Purpose : StrConv converts a string into the specified format.

Syntax :
StrConv ( strExpression , conversionType )

strExpression : String you want converted
conversionType : Constant indicating the conversion type

1 : vbUpperCase = Uppercases the entire string
2 : vbLowerCase = Lowercase the entire string
3 : vbProperCase = Uppercase the first letter in each word in the string

Dim strOldString as String , strNewString as String
strOldString = "arvind NAHAR"
strNewString = StrConv ( strOldString , vbProperCase )

Result is "Arvind Nahar"

Visual Basic String Function : StrComp

Purpose : strComp compares two strings

Syntax :
StrComp ( strString1 , strString2 [ , compareType% ] )

strString1 : First string you want to compare
strString2 : Second string your want to compare
compareType% : 0 for case-sensitive comparison , 1 for non-case-sensitive comparison.

Return value of the strComp Function
strString1< strString2 = -1
strString1 = strString2 = 0
strString1 > strString2 = 1
Either string is null = Null

hilo = strComp ( in$ , old$ )

Saturday, August 14, 2010

Visual Basic String Function : Str

Purpose : The Str function converts numeric data into an unformatted string.

Syntax :
str ( number )

number : Numeric data to convert to a string

s = Str ( txtNumber.Text )

The Str function translates a number into a string or byte array. Str does not formatting.

Visual Basic String Function : Split

purpose : Split examines an expression and parses out substrings based on a specified delimiter.The substrings that are parsed out are placed into a zero-based array.

Syntax :
Split ( expression [ , delimiter [ , count [ , compare ] ] ] )

expression : String value to be processed.
delimiter : String value identifying one substring from another. If this value is omitted, a blank space ( " " ) is used a s the delimiter.
count : Indicator how many time through the expression the function loops . if this value is omitted, the entire expression is processed.
compare : Indicator for the type of comparison between the delimiter and the expression.

0 : vbBinaryCompare
1 : vbTextCompare
2 : vbDatabasecompare

sName = Split ( "Mr. Jonathan Smythe")

the result of the Split function crates a one-dimensional array in sName, where
sName(0) = "Mr."
sName(1) = "Jonathan."
sName(2) = "Smythe."

Visual Basic String Function : Space

Purpose : The Space function returns a string containing the specified number of spaces.

Syntax :
Space ( lngNumSpaces )

lngNumSpaces : Number of spaces in the returned string

Dim strString as String
strString = Space ( 5 )

strString give the value of " " (five space)

Visual Basic String Function : RTrim

Purpose : The RTrim function returns a copy of a string with any trailing spaces removed.

Syntax :
RTrim ( String )

String : String to be modified.

rs!LastName = RTrim ( txtLastName.Text )

RTrim removes any spaces from the end of strings and byte arrays.

Visual Basic String Statement : RSet

Purpose : The RSet statement copies one string into another, byte by byte, starting at the rightmost character in the source string and working to the left.

Syntax :
RSet resultvariable = sourcevariable

resultvariable : Destination string for the assignment
sourcevariable : String value you want to assign to the destination variable

Private strNumberBuffer as String *12
Dim sugAmount as Single
Dim strAmount as String
sngAmount = 2003.45
strAmount = Format ( sngAmount , "#,###,###.#0" )
RSet strNumberbuffer = strAmount
lblBuffer.Caption = strNumberBuffer

Rset to right justify the string representation of a number in a label object.
Result is " 2,003.45"

Friday, August 13, 2010

Visual Basic String Function : Round

Purpose : Round returns a number that is rounded based on a specified decimal placement value.

Syntax :
Round ( expression [ , numdecimalplaces ] )

expression : A numeric value that is to be rounded.
numdecimalplaces : A number indicating how many numbers to the right of the decimal will be included in the rounding.

lValue = Round ( 186232.90260 , 3)

The number value that is stored in iValue is 186232.903 and if numdecimalplaces argument is nothing then value is 186233.

Visual Basic String Function : Right

Purpose : The Right function return a portion of a string , starting at the last character and working to the left , for the length specified.

Syntax :
Right ( strExpression , ingLength )
RightB ( strExpression , ingLength )

strExpression : Specifies the string for which you want the ingLength rightmost characters
ingLength : Specifies the number of characters of the returned substring.

Dim strHello as String , strDolly as String
strDolly = "Hello, Dolly!"
strHello = Right ( strDolly , 6)

In this code the rightmost six characters from strHello to the variable strDolly , giving it a value of "Dolly!".

Visual Basic String Function : Replace

Purpose : Replace enables you to substitute a specified string value within a given string for a specified number of times.

Syntax :
Replace ( expression, find , replacewith [ , start [ , count [ , compare ] ] ] )

expression : String value containing the value to be replaced.
find : String value being searched for.
replacewith : String value to replace the value specified in the find argument.
start : Position within the expression from which to start the search for the find string value .
count : Number of times the find and replace will be performed within the string expression.
compare : Numeric value indicating the kind of comparison to use when evaluating substrings
0 : vbBinaryCompare
1 : vbTextCompare
2 : vbDatabaseCompare.

s = Replace ( "Michael Smith Jr. " , "Smith" , "Smythe" , compare : = vbBinaryCompare )

Thursday, August 12, 2010

Visual Basic String Statement : Option Compare

Purpose : use the Option Compare statement to control how string comparisons are made.

Syntax :
Option Compare ( Binary | Text)

Visual Basic defaults to using a binary comparison method when comparing two string. binary comparisons are case sensitive, so " A " does not equal " a " . the relative order of characters is determined by their order in the ANSI character set.

Text comparisons are not case sensitive, so " A " does equal " a ".Furthermore , the relative order of characters is determined by the international section of WIN.INI.

Visual Basic String Function : MonthName

Purpose : MonthName return the name of the month in which the numeric equivalent was passed.

Syntax :
sMonth = MonthName ( MonthNbr , [ Abbrev ] )

MonthNbr : A numeric value designating a month.
Abbrev : A Boolean value that indicates whether the month will return abbreviated or fully spelled out. The default value is False ; therefore, if this argument is omitted, the month is fully spelled out. Abbrev is optional.

Function SpellMonth ( sString as String ) as String

If IsNumeric ( sString ) Then
If Val ( sString ) > 0 And Val ( sString ) < 13 Then
SpellMonth = MonthName ( sString)
Else
MsgBox sString & " is not a valid entry "
End If
Else
MsgBox sString & " is not a valid entry "
End If

End Function

Visual Basic String Statement : Mid

The Mid statement enables you replace the characters at an arbitrary location in a string.

Syntax :
Mid ( strResultString , ingStart [ , ingLength ] ) = strExpression
MidB ( strResultString , ingStart [ , ingLength ] ) = strExpression

strResultString : String in which you want to replace a substring with another substring.
ingStart : Starting position for the replacement
ingLength : Number of characters of the substring to be replaced
strExpression : Replacement value for the substring

Dim strHello as String
strHello = "Hello, Dolly"
Mid ( strHello , 1 , 5 ) = "Oh my"

Mid ( strHello , 8 ) = "Beck"

The first example replaces "Hello" in strHello with "Oh my". The second example starts at the eighth position and replaces whatever text is there with "Beck". Because the length is not specified , the replacement is effective for the length of "Beck". This makes strHello's final value "Oh my, Becky"

Visual Basic String Function : Mid

Purpose : The Mid functions the specified portion of a string expression.

Syntax :
Mid ( strExpression , ingStart [ , ingLength ] )
MidB ( strExpression , ingStart [ , ingLength ] )

strExpression : Specifies the string from which you want to return a substring.
ingStart : Specifies the starting position for the returned substring.
ingLength : Specifies the number of characters of the returned substring.

Dim strGood as String
Dim strBye as String , strDolly as String
strGood = "Good bye, Dolly"
strBye = Mid ( strGood, 6 , 3 )
strDolly = Mid ( strGood , 11 )

The first example uses the Mid function to assign the value " bye " to the variable strBye. In the second example, the length parameter is omitted so the string returned starts where indicated and continues for the balance of then length of strGood . Therefore , the variable strDolly is assigned the value " Dolly "

Wednesday, August 11, 2010

Visual Basic String Statement : LTrim

Purpose : LTrim removes leading spaces from a string or byte array.

Syntax :
LTrim ( string )

string : The string being trimmed

ds!Name = LTrim ( txtName.Text )

LTrim removes all leading spaces form a string or byte array. LTrim generally is used with data entered on a form to make sure no extraneous spaces are stored with the data.

Visual Basic String Statement : LSet

Purpose : Lset moves data from one string or user-defined type(UDT) to another. when LSet is used to move data from one variable to another, the data in the "from" variable is placed left justified in then "to" variable.

Syntax :
LSet s1 : s2

s1 : String or UDT that will receive the new data. It's the " to" variable.
s2 : String or UDT that will sending the data. It's the " from" variable.

Private Type OneType
a as string * 10
b as Integer
c as Long
End Type
Private Type TwoType
a as String * 10
b as Integer
c as Long
End Type

Private Sub cmdLSet_Click ()
Dim ot as OneType
Dim tt as TwoType
ot.a = "Arvind"
ot.b = 2
ot.c = 3

LSet tt = ot
Debug.Print tt.a , tt.b , tt.c

End Sub

Debug.Print return "Hi" 2 3

If Len ( Text1 ) < 20 Then
LSet sLeft = Text1
Picture1.Print "LSet : " ; Tab (30) ; sLeft
RSet sRight = Text1
Picture1.Print "RSet " " ; Tab (30) ; sRight
End If

This code show the difference between LSet and RSet string.

Visual Basic String Function : Len

Purpose : The Len function return the storage length of a variable. They are most commonly used to find the length of a string.

Syntax :
Len ( variable-name )

variable-name : The name of Visual Basic variable for which you want to determine the storage length.

Dim strHello as String
Dim ingStrLen as Long
strHello = "Hello"
ingStrLen = Len( strHello )

Because the string "Hello" contains five characters , this places the value 5 into the variable ingStrLen.

Visual Basic String Function : Left

Purpose : The Left functions return a portion of a variant or a string, starting at the first character , of the length specified.

Syntax :
Left (strExpression , IngLength )
LeftB ( strExpression , IngLength )

strExpression : Specifies the string from which you want to return then IngLenght leftmost characters.
IngLength : Specifies the number of characters of the returned substring.

Dim strDolly as String , strHello as String
strDolly = "Hello, Dolly!"
strHello = Left ( strHello , 5)

the five leftmost characters from strDolly to the variable strHello , giving it a value of "Hello".

Visual Basic String Function : LCase

Purpose : The LCase function returns a copy of a variant or a string in which all uppercase alphabetic characters have been converted to lowercase .

Syntax :
LCase ( strExpression )

strExpression : String you want converted to lowercase

Dim strCommandLine as String , strLowerCommand as String
strCommandLine = command
strLowerCommand = LCase ( strCommandLine )

This example retrieves the command -line parameters that were used to start the program and converts the entries to lowercase.

Tuesday, August 10, 2010

C Sharp : Using ref and out Parameter

When we pass a parameter as ref to a method, the method refers to the same variable and changes made will affect the actual variable.Even the variable passed as out parameter is similar to ref, but there are few implementation differences when you use it in C#.

Argument passed as ref must be initialized before it is passed to the method, where as in case of out its is not necessary,but after a call to the method as an out parameter the variable must be initialized.

When to use ref and out parameter. out parameter can be used when we want to return more than one value from a method.

IMPORTANT NOTE : We now know what are ref and out parameters, but these are only for C#(these are only understood by csc Compiler) when looking inside the IL Code there is no difference whether you use ref or out parameters. The implementation of ref and out parameter in IL Code is same.

When Calling a method and in the method signature after the datatype of the parameter a & sign is used, indicating the address of the variable.


Source Code:

RefOut.cs

using System;
class RefOut
{
public static void Main(String [] args)
{
int a = 0,b,c=0,d=0;

Console.WriteLine("a is normal parameter will not affect the changes after the function call");
Console.WriteLine("b is out parameter will affect the changes after the function call but not necessary to initialize the variable b but should be initialized in the function ParamTest ");
Console.WriteLine("c is ref parameter will affect the changes after the function call and is compulsory to initialize the variable c before calling the function ParamTest");
Console.WriteLine("d is used to store the return value");
d=ParamTest(a,
out b,ref c);
Console.WriteLine("a = {0}", a);
Console.WriteLine("b = {0}", b);
Console.WriteLine("c = {0}", c);
Console.WriteLine("d = {0}", d);
}
public static int ParamTest(int a, out int b, ref int c)
{
a=10;
b=20;
c=30;
return 40;
}
}

Save the Above File as RefOut.Cs , Compile C:\>csc RefOut.cs and Run C:\>RefOut

Visual Basic String Function : Join

Purpose : The Join function returns a string created by concatenating all the values with in array

Syntax :
Join ( ListArray , [ Delimiter ] )

List Array : A one-dimensional array containing the substring values that will be concatenated
Delimiter : A string value that separates the substring in ListArray . If the argument is omitted , the values are concatenated with no delimiters.

Dim sString
Dim vArray(2)
vArray(0) = "Mr."
vArray(1) = "Arvind"
vArray(2) = "Nahar"
sString = Join(vArray , "+ " )

The result of sString will be " Mr. + Arvind + Nahar "

Visual Basic String Function : InStrRev

Purpose : The InstrRev function returns the position of an occurrence of a search string within another string being searched ; it is similar to the IsStr function . However, unlike the InStr function, which search from left to right, InStrRev searches the string from right to left.

Syntax :
InStrRev ( strString1 , strString2 [ , IngStartPos [ , compare ] ] )

strString1 : String in which to search for strString2.
strString2 : String to be searched.
IngStartPos : Position in strString1 from which to start the search for strString2
compare : Numeric value indicating the kind of comparison to use when evaluating FindValue against the InputStr array. default value is vbBinaryCompare
0 : vbBinaryCompare
1 : vbTextCompare
2 : VbDatabaseCompare

Dim strBye as String
Dim ingPos as Integer
strBye = "Good Bye"

ingPos = (InStrRev ( strBye , "Bye" )

The argument strString1 is the string that will be searched. strstring2 is the string that is being searched for. If srrString2 is found within strString1 , InStrRev returns the position where the beginning of the search string is found . If the string cannot be found , a 0 is returned.

Visual Basic String Function : InStr

Purpose : The Instr function return the position of an occurrence of a search string within another string bing searched.

Syntax :
InStr ( [IngStartPos ] , strString1 , str Strine2 [ , compare ] )
InStrB ( [IngStartPos ] , strString1 , str Strine2 [ , compare ] )

IngStartPos : Position in strString1 from which to start the search for strString2
strString1 : String in which to search for strString2
strString2 : String to be searched
compare : Numeric value indicating the kind of comparison to use when evaluating FindValue against the InputStr array. default value is vbBinaryCompare
0 : vbBinaryCompare
1 : vbTextCompare
2 : vbDatabaseCompare

Dim strBye as String
Dim IngPos1 as Integer , IngPos2 as Integer
strBye = "Good Bye"

ingPos1 = InStr ( strBye , "Bye")
ingPos2 = InStr ( 7 , strBye , "Bye")

The first example assigns the value 6 to the variable IngPos1 because the string "Bye" can be found at the sixth position in strBye.
The second example starts the search at position 7; therefore , "Bye" cannot be found. the variable IngPos2 is assigned a value of 0.

Visual Basic String Function : Format

Purpose : The Format function take a string , number , or date variant and returns a formatted number , date or time.

Syntax :
Format ( expression , "format1; format2" , firstdayofweek , firstweekofyear )

expression : specifies the data to format
format1,2, ..... : Specifies how to format expression .Multiple formats are separated by semicolons. This argument is optional.
firstdayofweek : Used when formatting dates. This arguments is optional
firstweekofyear : Used when formatting dates. This arguments is optional

Formats Available

(0) : Displays a zero or a number.
(#) : Displays a number or nothing
( . ) : Displays a decimal point. the actual decimal point is based on the regional settings

SFormat = " Currency "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " ######.00 "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " 000000.## "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " Standard "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " General Number "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " Fixed "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " Percent "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )
SFormat = " Scientific "
Picture1.Print SFormat & " : " ; Tab(30) ; Format ( Val ( Text1) , SFormat )

Visual Basic String Function : Filter

Purpose : The Filter function searches through a given string array for a specified filter criterion and returns the value to a zero-bases array.

Syntax :
Filter(InputStr , FindValue [ , Include [ , Compare ] ] )

InputStr : A One-dimensional array that the function searches through
FindValue : A string value being searched for
Include : A Boolean argument that indicates whether to rerurn string that include or exclude FindValue string
Compare : A numeric value indicating the kind of comparison to use when evaluating FindValue against the inputStr array. by default value is vbBinaryCompare
0 : vbBinaryCompare
1 : vbTextCompare

Dim vIdx as Variant
Dim vArray(3)
Dim x as Integer
vArray(0) = "Forthy"
vArray(1) = "Forthy Two"
vArray(2) = "Four Hundred"
vArray(3) = Fantastic Four"
vIdx = Filter(vArray , "For")
For x = 0 To UBound(vIdx, 1 )
Debug.Print vIdx ( x )
Next

Visual Basic String Function : Chr

Purpose : The Chr function returns the character that corresponds to the supplied code

Syntex :
Chr(intANSICode)
ChrB(intANSICode)
ChrW(intANSICode)

intANSICode : integer for which you want to return the corresponding character.

Dim strDoubleQuote as string
strDoubleQuote = Chr(34)

This example places a double quote ( " ) in the variable strDoubleQuote.

Visual Basic String Function : Asc

Purpose : The Asc function return the numeric code of a character

Syntax :
Asc(strExpression)
AscB(strExpression)
AscW(strExpression)

strExpression : String for which you want to return the numeric code of the first character

Dim intAnsi as integer
intAnsi = Asc("Hello")

Return value is 72 because then ANSI code for the character H

Differences between procedures and functions?

Difference 1:
A : Stored procedure will be used for perform specific tasks
B : Normally functions will be used for computing value

Difference 2:
A : Stored procedures may or may not return values
B : But function should return value

Difference 3:
A : Stored procedure cannot be used in the select/where/having clause
B : But function can be called from select/where/having clause

Difference 4:
A : Stored procedure can run independently. It can be executed using EXECUTE or EXEC command
B : But function cannot run independently

Difference 5:
A : Temporary table (derived) cannot be created on function.
B : But it can be created in stored procedures

Difference 6:
A : Stored procedure can call the user defined functions
B : But the function cannot call the stored procedures.

Difference 7:
A : From sql server 2005 onwards, TRY CATCH statements can be used in the stored procedures.
B : But it cannot be used in the function. But we can use raise error function.

Difference 8:
A : Stored procedures can have input and output parameters.
B : But the function can have only input parameters.

Difference 9:
A : Stored procedures can have select and all DML operations.
B : But the function can do only select operation.

Difference 10:
A : Function cannot have the transaction statements.
B : Stored procedure can use transaction statements.

Difference 11:
A : Stored procedures can use all the data types available in sql server.
B : But the function cannot use the ntext, image and timestamp data types as return type.

Difference 12:
A : Stored procedures can create table variable and cannot return the table variable.
B : But the function can create, update and delete the table variable. It can return table variable.

Difference 13:
A : Stored procedure can have the dynamic sql statement and which can be executed using sp_executesql statement.
B : But the function cannot execute the sp_executesql statement

Difference 14:
A : Stored procedure allows getdate () or other non-deterministic functions can be allowed.
getdate(),DB_ID(),DB_NAME ()
B : But the function won't allow the non-deterministic functions.