+-------------+ |VAL Function | +-------------+ ->Basically used to convert the text data entered in controls to numeric type. ->For eg:Consider a textbox in the form where the user is asked to enter the number,but if in case he enters String then using val function we can convert the input into numeric type. ->Syntax: Val(Expressiontoformat) ->Examples: curPrice=Val(txtPrice.Text) intQuantity=Val(txtQuantity.Text) ->Val function begins with the arguments left-most corner. ->If that character is numeric/digit/sign,it converts the character to numeric and moves to the next character. ->As soon as non-numeric character is found,the operation stops.Few examples are given below Contents of Argument O/P returned by Val -------------------- ------------------- (blank) 0 123.45 123 $100 0 1,000 1 A123 0 4b5 4 -123 -123 12.34.5 12.34 --------------------------------------------------------------- +---------------------+ |Arithmetic Operations| +---------------------+ Various operators discussed here are Addition + Subtraction - Multiplication * Division / Exponential ^ Order of Operation ------------------ 1.Exponential 2.Multiplication and division 3.Addition and subtraction Note-> If there is a tie between operators of ----- same precedence,the operation takes place fro left to right. For eg:8/4*2 will yield the answer as 4 and not as 1. Few points are taken into consideration: ---------------------------------------- 1.All operations withing the parentheses.Multiple operations within parentheses are performed according to the rule of precedence. 2.All Exponential. Multiple operations are performed from left to right. 3.All mul and div.Multiple operations are performed from left to right. 4. All addition and subtractionare performed from left to right. ------------------------------------------------------------ +---------------+ |Data Formatting| +---------------+ ->VB has a built in formatting functions which can be used to convert data from one format to another. ->Various types of formatting functions are divided into following four types ____________________________________________________________ Format Functions | + +----------+------------+---------------+ | | | | FormatCurrency FormatNumber FormatPercent FormatDateTime ____________________________________________________________ 1.FormatCurrency -------------- ->This function returns the string of characters formatted as dollars and cents. ->Default: Dollar sign($),commas,and two positions to the right of decimal point. ->Syntax:FormatCurrency(NumericExpressionToFormat) -> Eg: lblBalance.Caption=FormatCurrency(curBalance) Variable Value Function Output -------- ------ --------- ------ curBalance 1275.675 FormatCurrency(curBalance) $1,275.68 sngAmount 0.9 FormatCurrency(sngAmount) $0.90 ->General Form: FormatCurrency(ExpressionToFormat[,NumberOfDecimalPositions [,LeadingDigit[,UseParenthesisForNegative[, GroupingForDigits]]]]). 2.FormatNumber ------------ ->Similiar to format currency function but used purely with numbers. ->Default: Displays commas and two digits to the right of decimal point. ->EG: lblWholeNumber.Caption=FormatNumber(intCount,0) ->General Form: FormatNumber(ExpressionToFormat[,NumberOfDecimalPositions [,LeadingDigit[,UseParenthesisForNegative[, GroupingForDigits]]]]) Variable Value Function Output -------- ------ --------- ------ mcurTotal 1125.67 FormatNumber(mcurTotal,0) 1126 curBalance 1234.567 FormatNumber(curBalance,2) 1234.57 3.FormatPercent -------------- ->Expresses the value of given expression in terms of its percentage.(Multiplies the number by 100) ->Default: Displays commas and two digits to the right of decimal point. ->EG: lblPErcentComplete.Caption=FormatPercent(sngComplete) lblInterestRate.Caption=FormatPercent(curRAte) ->General Form: FormatPercent(ExpressionToFormat[,NumberOfDecimalPositions [,LeadingDigit[,UseParenthesisForNegative[, GroupingForDigits]]]]) Variable Value Function Output -------- ------ --------- ------ curCorrect 0.75 FormatPercent(curCorrect,1) 75.0% curRate 0.734 FormatPercent(curRate,2) 73.40% 4.Format DateTime --------------- ->Syntax: FormatDateTime(ExpressionToFormat[,NamedFormat]) ->The expression may be a string that holds a date or time that holds the date and time value,a date type variable,or a function that returns a date. ->If the optional named format is omitted, the function returns the date using vbGeneralDate. -------------- ->Eg: lblStartDate.Caption=FormatDateTime(dtmStartDate, vbShortDate) lblStartDate.Caption=FormatDateTime("1/1/00",vbLongDate) Note:The actual values returned by FormatDateTime function ----- depends on the regional settings on your computer. Named Format Returns Example ------------ --------- -------- vbGeneralDate date and/or time 2/28/99 6:01:24PM vbLongDate Day of week, Sunday,May 28,1998 Month Day,Year vbShortDate MM/DD/YY 2/28/99 vbLongTime HH:MM:SS AM/PM 6:01:24 PM vbShortTime HH:MM(24 hour clock) 18:01