
<p> CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Format function: Format$(Expression, formatting string) or Format(Expression, FS) Examples Results Format$(3000, “Currency”) $3,000.00 Format$(3000.1, “Fixed”) 3000.10 Format$(.25, “Percent”) 25.00% Format$(1234, “Scientific”) 1.234E+03 Format$(3000, “Standard”) 3,000</p><p>Evaluate the following and determine the results. Remember to look at prefixes to determine the argument type. Cash = 3250.75 Function Results lblNetCash = format( intCash, “Standard”) lblNetCash = format( intCash, “Currency”) lblNetCash = format( intCash, “Percent”) lblNetCash = format( intCash, “Scientific”) lblNetCash = format( intCash, “Fixed”)</p><p>Mathematical Functions: Function Returns Example Result Abs(x) Absolute value of x Abs(-3.2) 3.2 Cos(x) Cosine value of x where x is an Cos(3.14159265359) -1 angle in radians Exp(x) ex Exp(1) 2.71828182845905 Fix(x) Integer portion of x by Fix(3.6) 3 truncation Int(x) Integer portion of x by Int(3.6) 3 truncation Log(x) Natural logarithm of x Log(2.71828182845905) 1 Rnd() A random number in the range Rnd() Any random number of (0 to 1) (but less than 1) between 0 and 1 Sgn(x) Sign (1,0 or –1) of x Sgn(-9) -1 Sin(x) x, where x is an angle in Sin(0) 0 radians Sqr(x) Square root of x Sqr(100) 10 Tan(x) Tangent of x where x is a Tan(100) -0.58721 radiant</p><p>Evaluate the following and determine the results. Remember to look at prefixes to determine the argument type.</p><p>Function Results Abs(202.50 – 1525.456) Log(3.14159265359) Sqr(5000) Sgn(-25) CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Int(-12535.9999) Fix(-12535.9999)</p><p>Conversion Functions –x is an expression that can be evaluated to a numeric value Function Returns Example Results CBool(x) Boolean type value CBool(1) True all non-zero values convert to true CByte(x) Byte (character) CByte(“12”) 12 CCur(x) Currency type CCur(“12.34”) 12.34 CDate(x) Date/Time type CDate(“31-Dec-02”) 12/31/02 CDbl(x) Double type CDbl(“12.34”) 12.34 CDec(x) Decimal type CDec(“12.34”) 12.34 CInt(x) Integer type CInt(“12.34”) 12 CLng(x) Long type CLng(“12.34”) 12 CSng(x) Single type CSng(“12.34”) 12.34 EOF(ChannelNo) Checks for end of If EOF(1) then When the end of file markers file is reached it will be true</p><p>Evaluate the following and determine the results. Remember to look at prefixes to determine the argument type. TxtHourRate = 16.75 txtHours = 40.25 Function Results dblSalary = Cdbl(txtHourRate) * Cdbl(txtHours) intSalary = CInt(txtHourRate) * CInt(txtHours) curSalary = CCur(txtHourRate) * CInt(txtHours) lngSalary = CLng(txtHourRate) * CCur(txtHours) DtmReportDate = CDate(Now) </p><p>Date and Time Functions</p><p>Function Returns Example Result Date Current date of Date Today computer Now Current date and Now Current date time of computer & Time Time Current time of Time Current time computer DateSerial(Date) Date given y m d DateSerial(00,5,31) 05/31/00 DateValue(Date) Date given a date in DateValue(“May 31,00”) 05/31/00 string DateAdd(Date) Date and time after DateAdd(“m”,2,”03/31/00”) 05/31/00 adding the specified date by the specified number of intervals. Year(date) The year of a date Year(Now) 2002 CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Month(date) The month of a date Month(Now) 11 Day(Date) The day of a date Day(Now) 12</p><p>Evaluate the following and determine the results. Remember to look at prefixes to determine the argument type. Assume Now is equal to the system date below. TxtDate = “11/12/02” system date = 11/12/02 1:12:20 PM Function Results Month(txtDate) DateSerial(Now) Now DateAdd(“m”, 5, txtDate) DateAdd(“d”, 20, Now) PicDisplay.Print “Month = “ ; Month(txtdate)</p><p>String Functions Function Returns Example Result Asc(char) The ASCII value of the character Asc(“A”) 65 Chr(n) The ASCII character represented by Chr(65) A n Replace(s, fs, rs, p,c) A string that has the findstring (fs) Replace(“My “Your replaced with the replacementstring Name”,”MY”,”Your”,1,1) Name” (rs) given a starting position p, and replaced c number of times. Val(s) Converts s to a number Val(“$21.00”) 21.00 Str(n) Converts n into a string Str(65) “65” StrReverse(s) The mirror image of s StrReverse(“AB”) “BA” Lcase(s) All lower case of s Lcase(“DEBY”) “deby” Ucase(s) All upper case of s Ucase(“deby”) “DEBY” Space(n) Generates a string of n blank spaces Space(5) “ “ String(n,char) Creates a string with n repetitive String(3,”A”) “AAA” characters Left(s,n) A subset of s consisting of n Left(“My Name”,2) “MY” characters beginning with the left most character Right(s) A subset of s consisting of n Right(“My Name”,2) “me” characters beginning with the right most character Mid(s,b,n) A string of characters consisting of n mid(“My Name”,2,3) “y N” characters beginning at b position. If n is omitted it returns the remainder InStr(sp,s,m) The position in s where string m InStr(1,“My Name”, ”me”) 6 starts, the comparison begin at sp. 1 is the default of sp InStrRev(s,m,sp) The position in s where string m InStrRev(“My Name” , “me”) 6 starts, the comparison goes backwards from position sp. if omitted it begins at the end of s Len(s) The number of characters in s Len(“My Name”) 7 Ltrim(s) Removes all leading blanks in s LTrim(“ My “) “My “ Rtrim(s) Removes all trailing blanks in s Rtrim(“ My “) “ My” Trim(s) Removes leading and trailing blanks Trim(“ My “) “My” in s CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Evaluate the following and determine the results. Remember to look at prefixes to determine the argument type. Assume Now is equal to the system date below. s = “ This is my favorite class this semester. ” Function Value of strAnswer of intAnswer IntAnswer = Asc(“z”) StrAnswer = Chr(101) StrAnswer = Right(s,8) StrAnswer = Mid(s, 3, 4) StrAnswer = Mid(s,33) StrAnswer = lTrim(s) IntAnswer = Instr(s, “my”) IntAnswer = Instr(1, s, “is”) IntAnswer = Instr(5, s, “is”) IntAnswer = Instr(5, s, “Is”) IntAnswer = RevInstr(s, “is”) IntAnswer = Len(s) PicDisplay.Print String(10, “@”) PicDisplay.Print String(10, “AB”) Ucase(mid(s, 9, 6)) Chr(int(101.33333))</p><p>Both the “+” and the “&” can be use for concatenation operations but have different results. Evaluate the following. Dim strAnswer as string Value of strAnswer StrAnswer = “123” + “123” StrAnswer = “123” + 123 StrAnswer = “ABC” + 123 StrAnswer = “123” &”123” StrAnswer = “123” & 123 StrAnswer = “ABC” & 123</p><p>The Functions Val(s) and Str(n) Remember Val(s) converts s to a number and Str(n) converts n to a string, However Str(n) will add a leading space to the string. Function Result Val(“03-01-02”) Str(576) Val(“$50.00”) Str(50.00)</p><p>What numeric values do the following MsgBox functions display? True is internally coded as a two byte integer with all its bits on &HFFFF which = -1 False is internally coded as a two byte integer will all its bits off &H0000 which = 0 Function Value MsgBox "10 times True is " & 10 * True MsgBox "10 Plus True is " & 10 + True MsgBox "10 times False is " & 10 * False MsgBox "10 Plus False is " & 10 + False CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Functions for determining data types Function Purpose Example Returns IsArray(v) Verify Array IsArray(strName()) True or False IsNumeric(v/o) Verifies content of IsNumeric(txtValue) True or False variable or object IsDate(v/o) Verifies content of IsDate(dtmStartDate) True or False variable or object IsObject(v) Verifies content of IsObject(Customer) True of False variable or object Is Nothing Verifies content has If Customer Is True or False been set to nothing Nothing then TypeOf Checks the type of an If TypeOf txtName is True of false object variable. This TextBox then can be used only in a logical expression TypeName(v) Returns the data type PicDisplay.Print Returns the type name of a variable TypeName(strSalary) String, Integer, etc.</p><p>Some interesting VB Constants Constant Value Description</p><p> vbBlack &h00 Black</p><p> vbRed &hFF Red</p><p> vbGreen &hFF00 Green</p><p> vbYellow &hFFFF Yellow</p><p> vbBlue &hFF0000 Blue</p><p> vbMagenta &hFF00FF Magenta</p><p> vbCyan &hFFFF00 Cyan</p><p> vbWhite &hFFFFFF White</p><p>Constant Value Description</p><p> vbBinaryCompare 0 Perform a binary comparison.</p><p> vbTextCompare 1 Perform a textual comparison</p><p>Constant Value Description</p><p> vbSunday 1 Sunday</p><p> vbMonday 2 Monday</p><p> vbTuesday 3 Tuesday CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p> vbWednesday 4 Wednesday</p><p> vbThursday 5 Thursday</p><p> vbFriday 6 Friday</p><p> vbSaturday 7 Saturday</p><p> vbFirstJan1 1 Use the week in which January 1 occurs (default).</p><p> vbFirstFourDays 2 Use the first week that has at least four days in the new year.</p><p> vbFirstFullWeek 3 Use the first full week of the year.</p><p> vbUseSystem 0 Use the date format contained in the regional settings for your computer.</p><p> vbUseSystemDayOfWeek 0 Use the day of the week specified in your system settings for the first day of the week.</p><p>Constant Value Description</p><p> vbGeneralDate 0 Display a date and/or time. For real numbers, display a date and time. If there is no fractional part, display only a date. If there is no integer part, display time only. Date and time display is determined by your system settings.</p><p> vbLongDate 1 Display a date using the long date format specified in your computer's regional settings.</p><p> vbShortDate 2 Display a date using the short date format specified in your computer's regional settings.</p><p> vbLongTime 3 Display a time using the long time format specified in your computer's regional settings.</p><p> vbShortTime 4 Display a time using the short time format specified in your computer's regional settings.</p><p>Constant Value Description</p><p> vbOKOnly 0 Display OK button only.</p><p> vbOKCancel 1 Display OK and Cancel buttons.</p><p> vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.</p><p> vbYesNoCancel 3 Display Yes, No, and Cancel buttons.</p><p> vbYesNo 4 Display Yes and No buttons.</p><p> vbRetryCancel 5 Display Retry and Cancel buttons.</p><p> vbCritical 16 Display Critical Message icon.</p><p> vbQuestion 32 Display Warning Query icon. CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p> vbExclamation 48 Display Warning Message icon.</p><p> vbInformation 64 Display Information Message icon.</p><p> vbDefaultButton1 0 First button is the default.</p><p> vbDefaultButton2 256 Second button is the default.</p><p> vbDefaultButton3 512 Third button is the default.</p><p> vbDefaultButton4 768 Fourth button is the default.</p><p> vbApplicationModal 0 Application modal. The user must respond to the message box before continuing work in the current application.</p><p> vbSystemModal 4096 System modal. All applications are suspended until the user responds to the message box.</p><p>The following constants are used with the MsgBox function to identify which button a user has selected. These constants are only available when your project has an explicit reference to the appropriate type library containing these constant definitions. For VBScript, you must explicitly declare these constants in your code. </p><p>Constant Value Description</p><p> vbOK 1 OK button was clicked.</p><p> vbCancel 2 Cancel button was clicked.</p><p> vbAbort 3 Abort button was clicked.</p><p> vbRetry 4 Retry button was clicked.</p><p> vbIgnore 5 Ignore button was clicked.</p><p> vbYes 6 Yes button was clicked.</p><p> vbNo 7 No button was clicked.</p><p>Constant Value Description</p><p> vbCr Chr(13) Carriage return</p><p> vbCrLf Chr(13) & Carriage return–linefeed combination Chr(10)</p><p> vbFormFeed Chr(12) Form feed; not useful in Microsoft Windows</p><p> vbLf Chr(10) Line feed</p><p> vbNewLine Chr(13) & Platform-specific newline character; whatever is appropriate for Chr(10) or the platform Chr(10) CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p> vbNullChar Chr(0) Character having the value 0</p><p> vbNullString String having Not the same as a zero-length string (""); used for calling value 0 external procedures</p><p> vbTab Chr(9) Horizontal tab</p><p> vbVerticalTab Chr(11) Vertical tab; not useful in Microsoft Windows</p><p>Constant Value Description</p><p> vbEmpty 0 Uninitialized (default)</p><p> vbNull 1 Contains no valid data</p><p> vbInteger 2 Integer subtype</p><p> vbLong 3 Long subtype</p><p> vbSingle 4 Single subtype</p><p> vbSingle 5 Double subtype</p><p> vbCurrency 6 Currency subtype</p><p> vbDate 7 Date subtype</p><p> vbString 8 String subtype</p><p> vbObject 9 Object</p><p> vbError 10 Error subtype</p><p> vbBoolean 11 Boolean subtype</p><p> vbVariant 12 Variant (used only for arrays of variants)</p><p> vbDataObject 13 Data access object</p><p> vbDecimal 14 Decimal subtype</p><p> vbByte 17 Byte subtype</p><p> vbArray 8192 Array</p><p>Key Words Write the correct VB statement using the following Key Words. Use strFileName as the file variable KeyWord VB Statement Open (mode output) Explain what the mode does Rewrite the open statement using App.Path Explain what App.Path does Close (both examples) Explain the difference CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Write (strName, curSalary) Use Harry Potter and 500000 as data and show how the data will be stored on the disk. Input (use arguments from the write statement) What do we use the Input statement for? Dim (strName, curSalary) What does the Dim key word do? Const (dtmDate = today) What is the difference between a Constant and a regular variable? What is the difference between an argument and an attribute ByVal write a sub procedure statement for GetSalary and pass the arguments from the Dim statement. Pass the Name ByVal. What does the ByVal keyword do? Static declare strCompany as static How is a static argument different from a regular local argument? Rem or (‘) What is a Rem statement? Where should they be used? Call Write a call statement to call a procedure GetName include the two arguments in the Dim statement Write a user defined Function call statement to GetName and store the results in strCompanyName. Use the arguments from the call statement above. </p><p>Logic Structures Structure Statement Simple (If Then) Write an if the condition statement to add 1 to intCounter if sngGrade > 90 If Then Else Write an If then else block that adds 1 to intCounter if sngGrade > 90 or displays a message “You did not receive an A” Select Case selector Write a select case block which checks the value of Day(dtmToday) and displays the name of the day of the week. Only do the first two cases. Do While | Until Condition CSC 110 BUILT IN FUNCTIONS WORK SHEET 4/8/2018</p><p>Name ______</p><p>Create a loop structure that reads until the EOF(1) and inputs the data into string arrays strName() and strAddress(). What is the conditional difference between the Do Until and the Do While loops? Do loop Until | While condition Create a do loop while structure that checks the user input into txtPassword checking for “Master” For Next [step] Write a for next structure that reads the data from a sequential file and loads it into arrays strName() and strAddress() for 100 records. Use intCustNo as the index. Write a for next structure to read the above data but only store every other record in the arrays.</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-