Presentation is loading. Please wait.

Presentation is loading. Please wait.

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);

Similar presentations


Presentation on theme: "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);"— Presentation transcript:

1 Chapter 3 - Visual Basic Schneider

2 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: 2.6 6 6.8 Chapter 3 - Visual Basic Schneider

3 Function: Left(“Penguin”, 4) Purpose: Returns the number of characters specified, starting at the beginning of the string Chapter 3 - Visual Basic Schneider

4 Function: Right(“Gotham City”, 4) Purpose: Returns the number of characters specified from the end of the string Chapter 3 - Visual Basic Schneider

5 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

6 Function: UCase(“Yes”) Purpose: Converts any lowercase letters in a string to uppercase Chapter 3 - Visual Basic Schneider

7 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

8 Function: Len(“John Smith”) Purpose: Returns the number of characters in the string. Chapter 3 - Visual Basic Schneider

9 picBoard.print len(left(“welcome”,3)) picBoard.print UCase(left(“welcome”,3)) Chapter 3 - Visual Basic Schneider

10  The format functions provide detailed control of how numbers, dates, and strings are displayed.  Examples ◦ FormatNumber (12345.678, 1) 12,345.7 ◦ FormatCurrency (12345.678, 2) $12,345.68 ◦ FormatPercent (.185, 2) 18.50% ◦ FormatNumber (1 + Sqr(2), 3) 2.414 Chapter 3 - Visual Basic Schneider

11  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 of @ symbols. Chapter 3 - Visual Basic Schneider

12 Format(12345, “@@@@@”) 12345 Format(123, “@@@@@”) 123 Format(“123.4”, “@@@@@”) 123.4 Chapter 3 - Visual Basic Schneider

13

14

15

16 FormatDateTime (“9-15-04”, vbLongDate) Output: Monday, September 15, 2004 Chapter 3 - Visual Basic Schneider

17  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

18 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

19 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


Download ppt "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);"

Similar presentations


Ads by Google