Tuesday, August 31, 2010
Visual Basic Math Function : Hex
Hex ( numExpression )
numExpression : Numeric expression to be conerted to hexadecimal notation.
B$ = Hex ( A% )
This example places a string with thehexadecimal value "8C" into the variable B$.
Visual Basic Math Function : Oct
Oct ( numExpression )
numExpression : Numeric expression to be converted to octal notation.
Visual Basic Math Function : Str
Str ( numExpression )
numExpression : Numeric expression you want to convert to a string .
B$ = Str ( -100 )
The value of A$ becomes "100" and B$ "-100". string value return .
Visual Basic Math Function : Val
Val ( strExpression )
strExpression : String for which you want to return the numeric value
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
Tan ( dblAngle )
dblAngle : Numeric expression for which you want to return the tangent
dblResult = Tan (4.93 )
Visual Basic Math Function : Sqr
Sqr ( dblExpression )
dblExpression : Numeric expression of which you want to return the square root
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
Sin ( dblAngle )
dblAngle : Numeric expression for which you want to return the sine.
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
Sgn ( numExpression )
numExpression : Numeric expression for which you want to determine the sign.
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
Rnd [ ( lngExpression ) ]
lngExpression : A value that determines which number in the pseudo-random sequence to return ( optional )
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
Visual Basic Math Statement : Randomize
Randomize [ lngSeed ]
lngSeed : Seed number for a sequence of pseudo random numbers ( optional )
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
Monday, August 30, 2010
Visual Basic Math Function : Log
Log ( dblExpression )
dblExpression : Numeric expression for which you want to return the natural logarithm
dblNumber = 14
dblResult = Log ( dblNumber )
This example returns a double precision number that represents the natural logarithm for 14.
Visual Basic Math Function : Int
Int (numExpression )
numExpression : Numeric expression for which you want to return the largest integer less than or equal to it.
B% = Int ( 2.86 )
These statements place the value -3 in the variable A% and then value 2 in the variable B%
Visual Basic Math Function : Fix
Fix ( dblExpression )
dblExpression : Numeric expression of which you want to return the value with the fractional part truncated
Dim intResult as Integer
dblNumber = 54.72
intResult = Fix ( dblNumber )
intResult have value is 54
Visual Basic Math Function : Exp
Exp ( dblPower )
dblPower : Numeric expression repression representing the power to which you want to raise the number e.
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
Cos ( dblAngle )
dblAngle : Numeric expression for which you want to return the cosine
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 Math Function : Atn
Atn ( dblExpression )
dblExpression : Numeric expression for which you want to return the arctangent
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
Abs ( numExpression )
numExpression : Numeric expression of which you want to return the absolute value
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
Visual Basic String Function : WeekdayName
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
v
vbFriday
vbSaturday
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
UCase ( strExpression )
strExpression : String you want conerted to uppercase
Dim strUpperCommand as String
strCommand = Command
StrUpperCommand = UCase ( strCommand )
Visual Basic String Function : Trim
Trim ( string )
string : The string being trimmed
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
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
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
retStr = StrReverse ( String1 )
String1 = Specities the string that should have all its characters displayed in reverse
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
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
strOldString = "arvind NAHAR"
strNewString = StrConv ( strOldString , vbProperCase )
Result is "Arvind Nahar"
Visual Basic String Function : StrComp
StrComp ( strString1 , strString2 [ , compareType% ] )
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
Saturday, August 14, 2010
Visual Basic String Function : Str
str ( number )
number : Numeric data to convert to a string
The Str function translates a number into a string or byte array. Str does not formatting.
Visual Basic String Function : Split
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
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
Space ( lngNumSpaces )
lngNumSpaces : Number of spaces in the returned string
strString = Space ( 5 )
strString give the value of " " (five space)
Visual Basic String Function : RTrim
RTrim ( String )
String : String to be modified.
RTrim removes any spaces from the end of strings and byte arrays.
Visual Basic String Statement : RSet
RSet resultvariable = sourcevariable
resultvariable : Destination string for the assignment
sourcevariable : String value you want to assign to the destination variable
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
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.
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
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.
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
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.
Thursday, August 12, 2010
Visual Basic String Statement : Option Compare
Option Compare ( Binary | Text)
Visual Basic String Function : MonthName
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.
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
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
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
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 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
LTrim ( string )
string : The string being trimmed
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
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.
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
Len ( variable-name )
variable-name : The name of Visual Basic variable for which you want to determine the storage length.
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
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.
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
LCase ( strExpression )
strExpression : String you want converted to lowercase
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
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 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
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 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
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 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
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
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
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 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
Chr(intANSICode)
ChrB(intANSICode)
ChrW(in
intANSICode : integer for which you want to return the corresponding character.
strDoubleQuote = Chr(34)
This example places a double quote ( " ) in the variable strDoubleQuote.
Visual Basic String Function : Asc
Asc(strExpression)
AscB(strExpression)
As
strExpression : String for which you want to return the numeric code of the first character
intAnsi = Asc("Hello")
Return value is 72 because then ANSI code for the character H
Differences between procedures and functions?
A : Stored procedure will be used for perform specific tasks
B : Normally functions will be used for computing value
A : Stored procedures may or may not return values
B : But function should return value
A : Stored procedure cannot be used in the select/where/having clause
B : But function can be called from select/where/having clause
A : Stored procedure can run independently. It can be executed using EXECUTE or EXEC command
B : But function cannot run independently
A : Temporary table (derived) cannot be created on function.
B : But it can be created in stored procedures
A : Stored procedure can call the user defined functions
B : But the function cannot call the stored procedures.
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.
A : Stored procedures can have input and output parameters.
B : But the function can have only input parameters.
A : Stored procedures can have select and all DML operations.
B : But the function can do only select operation.
A : Function cannot have the transaction statements.
B : Stored procedure can use transaction statements.
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.
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.
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
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.