1 / 14

CS4 – lecture 6

CS4 – lecture 6. Wednesday, Jan 19, 2011 Roxana Gheorghiu. Numbers and Arithmetic Operations. Standard Arithmetic Operations: Addition (+) Subtraction (-) Division (/) Multiplication (*) Exponentiation (^) Level of precedence for arithmetic operations:.

lorant
Download Presentation

CS4 – lecture 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. Numbers and Arithmetic Operations • 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)

  5. Built-In Functions • 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

  6. Built-In Functions (cont.) • 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

  7. Assignment Statement 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

  8. String Properties and Methods 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”

  9. String Properties and Methods 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=“”

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

  11. Input Data from a Text Box 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

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

  13. Output Data Using a Message Box 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

  14. Application (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.

More Related