Prepared By: Deborah Becker Built-In Functions Chapter 3.6 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Topics Common Built-In Functions Numeric Functions Val() and Str() String Functions Formatting Functions 1/18/2019 Prepared By: Deborah Becker
Common Built-In Functions Types Formatting Numeric String Date & Time File handling 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Formatting & Printing Using the Print Zones Each line in a Picture box object or paper line is divided into zones. Each zone contains 14 positions about the size of a printed character We use the Print method of the picture box to display our output We use Commas and Semicolons to separate items on the print line Using Commas will display the data in different print zone Using Semicolons will display the data in a line with no spaces. 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Examples picDisplay.Print strName, strPhone 123456789012345678901234567890123456789 Deborah Becker (816)271-4521 picDisplay.Print strname; strPhone Deborah Becker(816)271-4521 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker The Tab() function Tab(n) This function is used to position data into the various positions on the print line n Represents the position on the line where the data item will print. Example picDisplay.Print strName; Tab(20); strPhone 123456789012345678901234567890 Deborah Becker (816)271-4521 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Spc() Function The Spc(n) function is used Print and Print# statements to generate spaces. Example picDisplay.Print strName; Spc(5); strPhone 12345678901234567890123456789 Deborah Becker (816)271-4521 1/18/2019 Prepared By: Deborah Becker
Common Numeric Functions Sqr(NumericVariable) Sqr(9) = 3 Sqr(319) = 17.86057 Int(NumericVariable) Int(3*5.9) = 17 Int(-2.7) = 3 The values inside the function can be number, numeric variables or numeric expressions Round(curPartPrice * IntQtyOrder, Digits) Round(2.356 * 5, 3) = 11.780 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Other Functions Val(Text Expression) User Input into TextBox Store results of Calculation Converts string variable to numeric value Produces an error if input is not numeric Useful is data is stored in string format Str(Numeric Expression) Converts Input in a TextBox to Numeric 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Solve These Functions sngPrice = Val(“3.16”)*5 sngPrice = int(3.16 * 5) sngPrice = Round(3.16*5) sngPrice = int(3.16) * 5 15.8 15 15.8 15 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker String Functions Left(strVariable,Number of Characters) Mid(strVariable, StartPosition,#Characters) Ucase(srtVariable) Trim(“ 1 2 “) Right(strVariable, Number of Characters) From the right most character Len(strVariable) Instr(strVariable, String Pattern) Returns the starting position in the string 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Solve These Examples Left(“CIS202”, 3) Right(“CIS202”,3) Mid(“Visual Basic”, 3, 2) Ucase(“visual Basic”) Lcase(“COMPUTERS”) Len(“Watcher, the Movie”) Instr(“Watcher, the Movie”, “at”) If the str2 is not a subset of str1 the values = 0 Else if str2 is a subset of str1 the value = the starting position of str2. (2) Trim(“ This class is too Early “) 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Date and Time Function FormatDateTime(dtmClassTime,vbLongDate) FormatDateTime(dtmClassTime,vbShortDate) Monday, September 18, 2000 09/18/00 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Formatting Numbers Format(FormatNumber(12345),@@@@@) The @ formating symbol is used to line up numbers and decimal points in output Format(FormatNumber(1234.5),@@@@@) FormatNumber() FormatCurrency() FormatPercent() FormatDateTime() 1/18/2019 Prepared By: Deborah Becker
Prepared By: Deborah Becker Setting TxtBox.Text txtBox.text = FormatNumber(1234.56,0) txtBox.text = FormatCurrency(123.45) txtBox.text = FormatCurrency(123.45,0) Use a format function to correctly display the following 1050.56 currency 09/18/00 long date 250.25 currency no cents 1/18/2019 Prepared By: Deborah Becker