Chapter 3 - Visual Basic Schneider
Private Sub cmdEvaluate_Click() Dim n As Single, root As Single n = 6.76 root = Sqr(n) picResults.Print root; Int(n); Round(n,1) End Sub Output: Chapter 3 - Visual Basic Schneider
Function: Left(“Penguin”, 4) Purpose: Returns the number of characters specified, starting at the beginning of the string Chapter 3 - Visual Basic Schneider
Function: Right(“Gotham City”, 4) Purpose: Returns the number of characters specified from the end of the string Chapter 3 - Visual Basic Schneider
Function: Mid(“Commissioner”, 4, 3) Purpose: Returns the substring starting at the position indicated by the first number and continuing for the length specified by the second number Chapter 3 - Visual Basic Schneider
Function: UCase(“Yes”) Purpose: Converts any lowercase letters in a string to uppercase Chapter 3 - Visual Basic Schneider
Function: InStr(“John Smith”, “m”) Purpose: Searches for the first occurrence of one string in another and gives the position at which the string is found Chapter 3 - Visual Basic Schneider
Function: Len(“John Smith”) Purpose: Returns the number of characters in the string. Chapter 3 - Visual Basic Schneider
picBoard.print len(left(“welcome”,3)) picBoard.print UCase(left(“welcome”,3)) Chapter 3 - Visual Basic Schneider
The format functions provide detailed control of how numbers, dates, and strings are displayed. Examples ◦ FormatNumber ( , 1) 12,345.7 ◦ FormatCurrency ( , 2) $12, ◦ FormatPercent (.185, 2) 18.50% ◦ FormatNumber (1 + Sqr(2), 3) Chapter 3 - Visual Basic Schneider
Format (expr, Purpose: The value of this function is the value of expr right justified in a field of n spaces, where n is the number symbols. Chapter 3 - Visual Basic Schneider
Format(12345, Format(123, 123 Format(“123.4”, Chapter 3 - Visual Basic Schneider
FormatDateTime (“ ”, vbLongDate) Output: Monday, September 15, 2004 Chapter 3 - Visual Basic Schneider
Returns a random number from 0 to 1. (excluding 1). Example: picBox.Print Rnd Output: Displays a random number from 0 to 1 (0 included and 1 excluded). Example: picBox.Print Rnd +5 Output: Displays a random number from 5 to 6 (5 included and 6 excluded). Chapter 3 - Visual Basic Schneider
Example: picBox.Print Int(Rnd) Output: Displays 0. Example: picBox.Print Int(Rnd +5) Output: Displays 5. Example: picBox.Print Int(Rnd) +5 Output: Displays 5. Chapter 3 - Visual Basic Schneider
Example: picBox.Print Int(5*Rnd) Output: Displays a random Integer from 0 to 4 (0 and 4 included). OR Output: Displays a random Integer from 0 to 5 (0 included and 5 excluded) Example: picBox.Print Int(5*Rnd) +2 Output: Displays a random Integer from 2 to 6 (2 and 6 included). Chapter 3 - Visual Basic Schneider