Unformatted text preview:

PowerPoint PresentationSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16PrecedenceSlide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36There are 3 integer types in VBSlide 38Slide 39Slide 40Slide 41Slide 42Slide 43Slide 44Slide 45Slide 46Slide 47Slide 48Slide 49Slide 50Slide 51Slide 52Slide 53Slide 54Slide 55When the button is clicked, the program control goes to the section marked… Private Sub btnEamonnDemo_Click (marked above with a black arrow) and runs the code there. In this case the code says… btnEamonnDemo.Text = “I was pressed!”So the Text property of the button is changed, and we see the result.This program is slightly different to the previous one.Note that we now want the text that we will assign the button to read “Fink Nottle”Once again, this program is only a trivial variation of the last program We now want the text that we will assign the button (after the click event) to read “777”It is to tedious to show the full screen for all teaching examples (and the text is too hard to read on the screen). So from now on, I will just show the relevant text, as in the above left. btnEamonnDemo.Text = "777"btnEamonnDemo.Text = “999”btnEamonnDemo.Text = “1 + 2”Not this!Everything inside the double quotes is a literal string, and appears exactly as is when displayedbtnEamonnDemo.Text = "Bertie" & " Wooster"We can join two literal strings together with the & symbol. (“&” is pronounced “ampersand”)In computer science, “joining” two strings is called concatenationbtnEamonnDemo.Text = "Bertie" & " Wooster"Note the space before “Wooster”. Recall these are literal strings, we get exactly what we specify.btnEamonnDemo.Text = "Bertie" & " Wilberforce" & " Wooster"We can use multiple concatenations to build long complex sentencesbtnEamonnDemo.Text = "Bertie" & " Wilberforce" & " Wooster"In future slides, I won’t bother showing the initial state of the program (the “Press Me!”), whenever its existence it obvious from contextbtnEamonnDemo.Text = "Bingo Little"btnEamonnDemo.Text = “1 + 2”Not this!Let us return to a previous example. We decided that the text above appears as a literal string.Suppose however we wanted the other case to happen. We want the math to be performed, and the result to be displayed…btnEamonnDemo.Text = (1 + 2).ToStringThe ToString method converts whatever is on the left side of the period and converts it to a string. We should never do … = ("1" + "2").ToStringAnymore than we could do … = (“Fish" + “John").ToString Addition is not meaningful for literal stringsWe should never do … = ("1" + "2").ToStringAnymore than we could do … = (“Fish" + “John").ToString Addition is not meaningful for literal stringsbtnEamonnDemo.Text = (2 + 2 + 2).ToStringThe ToString method works exactly like you might expect it to. It generalizes to longer and more complicated mathematical expressions (as we will see later)btnEamonnDemo.Text = "Today I am " & (5).ToString & " years old!"We can use the ToString method with the concatenation operator (&) to build up long expressions…= "Today I am " & (5).ToString & " years old!"“5”5These two things are very different for our purposes“5” is a literal string, that happens to contain the character we use to denote five.As a literal string the following code is legal…btnEamonnDemo.Text = “5” & “5”5 is a literal number (or just a number), that represents the mathematical intuition of five.As a number the following code is legal…btnEamonnDemo.Text = (5 + 5).ToStringPrecedencebtnEamonnDemo.Text = (2 + 6 / 2 ).ToStringorThe following code seems ambiguous… Is it… 2 + 6 / 28 / 242 + 6 / 22 + 35orIn fact, there is no ambiguity, because of the rules of precedence…Operators Operations()Parenthesis^Exponentiation* /Multiplication and Division+ -Addition and Subtractiondo.. firstlaterlast2 + 6 / 22 + 35So in our example, first do the expression in ParenthesisThere none in this example, next we do ExponentiationThere none in this example, next we do Multiplication and DivisionSo we divide 6 by 2 to get 3, next we doAddition and SubtractionSo we add 2 and 3 to get 5, we are done.Operators Operations()Parenthesis^Exponentiation* /Multiplication and Division+ -Addition and Subtractiondo.. firstlaterlast(2 + 6) / 28 / 24In this example, first do the expression in ParenthesisSo we add 2 and 6 to get 8, next we do ExponentiationThere none in this example, next do Multiplication and DivisionSo we divide 8 by 2 to get 4. next doAddition and SubtractionBut we are down to a single thing, 4. So we are doneOperators()^* /+ -do.. firstlaterlastIn this example, first do the expression in ParenthesisInside the parenthesis we find new expression, so we start work on just this expression, using the rules of precedence…When we are finished with the contents of the parenthesis, we are left with a single number (in this case 11), we replace the entire parenthesis with 11, and work on the new expression…(2 + 3 * 3 ) ^ 22 + 911 ^ 2121(2 + 3 * 3 ) ^ 2How aboutbtnEamonnDemo.Text = (2 + 6 / 2).ToStringbtnEamonnDemo.Text = (2 + (6 / 2)).ToStringSometimes, we use unnecessary parenthesis in our code, just to make our meaning explicit… The two lines of code above are logically identical, but the second one “jumps out” in saying, I want 6/2 to happen firstVariables (chapter 3 in text)In most computer problems, we need to remember (store) information.For example, a program that…• …calculates your GPA, needs to store all your grades• …does your taxes, needs to store…• …converts temperature, needs to store… We can store this information in variablesComputer MemoryImagine this is a computer memory. It is full of “containers” that can store information. I want to store my shoe size (12) and my age (21) Lets do it…Computer MemoryThere are a few problems with my naive example. • How can we tell which is which?• How do we know what type of data it is?1221We need to give each container a name, and a typeComputer Memory1221We need to give each container a name, and a type Now I can access the information, and update it if necessary. ShoeSizeAgeinteger integer So every container has a• name • type • valueSo every container has a• name • type • valueIn the


View Full Document

UCR CS 5 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?