Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.

Similar presentations


Presentation on theme: "CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu."— Presentation transcript:

1 CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu

2 Standard Arithmetic Operations: Addition (+) Subtraction (-) Division (/) Multiplication (*) Exponentiation (^) Level of precedence for arithmetic operations: Numbers and Arithmetic Operations

3 Standard Arithmetic Operations -Level of precedence for arithmetic operations: Addition (+) Subtraction (-) Division (/) Multiplication (*) Exponentiation (^) Numbers and Arithmetic Operations

4 Level of precedence for arithmetic operations: Addition (+) Subtraction (-)-LEVEL 3 Division (/) Multiplication (*)-LEVEL 2 Exponentiation (^) –LEVEL 1 NOTE: 1/0 = Infinity Math.Sqrt(-4) =NaN(Not a Number) Numbers and Arithmetic Operations

5 Modulo : x Mod y =the reminder when m is divided my n Ex: 20 Mod 2 =0 15 Mod 4 =3 Square root: Math.Sqrt( #number) Ex: Math.Sqrt(9) =3 Built-In Functions

6 The greatest integer less than or equal to a number: Int(#number) Ex: Int(2.7) =2 Int(-2.7) =-3 Rounding a number to r decimal places: Math.Round(#number, #r) or Math.Round(#number) Math.Round(2.14, 1) =2.1 Math.Round(2.67) =3 Built-In Functions (cont.)

7 Var = expression (1) Dim myNumber as Double myNumber =5.21 (2) Dim myNumber as Double =5.21 NOTE: Dim x as Integer =3, y as Double =5.3 Assignment Statement

8 Dim str as String =“ My own String ” Length() =returns the number of characters in the string str.Length ->19 ToUpper() =returns the string with letters capitalized str.ToUpper() ->” MY OWN STRING “ ToLower() =returns the string with all letters in lowercase format Str.ToLower() -> “ my own string “ Trim() =returns the string with all spaces removed from the front and back of the string str.Trim() -> “My own String” String Properties and Methods

9 Dim str as String =“ My own String ” Dim str2 as String = “own” Substring (m,n) =the substring that starts at position m and its n characters long IndexOf(newString) str.IndexOf(str2) =str.IndexOf(“own”) returns: 6 str.Substring(0,5) returns: “ My” Clear()=creates an empty string str.Clear() str.Txt=“” String Properties and Methods

10 CStr(number) or number.ToString converts a number into a string CInt(string) converts a String into an Integer value CDbl(string) converts a String into a Double value & used to concatenate two strings str =“One” ; str1 =“ and two” str & str1 returns: “One and two” _ the continuation character String Properties and Methods

11 stringVar =textBox.Text Ex: Dim str as String str =txtName.Text If the input data will be used in a MATH expression you will need first to convert it to Double or Integer and then use it Input Data from a Text Box

12 stringVar = InputBox(prompt, title) Ex: Dim name as String Dim prompt, title as String prompt =“Please give a name” title =“Input box for a name” name =InputBox(prompt, title) Input Data from Dialog Box

13 MsgBox(prompt, button, title) Ex: MsgBox (“Congratulation !”, 0, “Result Window”) OR MsgBox (“Congratulation !”) -> in this case the title is the same string as the name of the main window Note: check *Dailly Schedule* on www.cs.pitt.edu/~roxana/cs4/ for a complete list of possible values for variable button www.cs.pitt.edu/~roxana/cs4/ Output Data Using a Message Box

14 (1) Write a VB program that asks a name as input and it will copy that name in a list. (2) Write a VB program that asks a name as input and it will copy the first name in one list and the last name in another list (3) Continue exercise (2) by adding a new button Del, that will delete an entry selected from any list. Application


Download ppt "CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu."

Similar presentations


Ads by Google