Unit II — Actions (IPO); Data & Manipulations

CS 1130 Visual Basic—Fall 2016

Day 5 — Unit II: IPO

Logistics

Assignments

Hopefully, you created the project for the Unit I practice. I recently posted the Unit II assignment description. We're starting Unit II stuff. Remember to be thinking about what you would like/can do for a project. Feel free to talk with me about ideas you might have (I can suggest whether they are too small, too big, or just right).

We will start Unit II practice today and you should work on it outside of class, next time (we'll work on it some more) but I won't be here. I am planning to find someone to cover class for me so you can have some assistance while you work on the learning activity. The goal is to be done with it before class time next Tuesday.

Questions over Unit I?

If you are having any difficulty or do not feel comfortable with what we have been doing you need to contact me after class or tomorrow.

Unit II

Unit II introduces the common data and operation parts of programming. The data parts are literals, variables, and form element properties. They will mostly be numeric or text string (and some Boolean—True & False). The operations for numbers include addition, subtraction, multiplication, division, exponentiation, & modulus determination. The main operation for strings is concatenation (putting strings together to make another string).

Unit II also addresses the basic actions of programming—input, output, and process (typically using the assignment statement).

Once you become familiar with data, operations, and the three basic actions programming is just a manner of putting them together appropriately. It will be helpful to be thinking about storage and values. Storage (form element properties and variables) is where values can be placed or looked up. Values can be built or produced and then are often placed in storage. Values can also displayed to the user or put in a file (output). Finally, values can come from the user (input) and be placed in storage. Let's look at storage and values for each of the actions.

Assignment Statement

An assignment statement has the following form:

    memoryLocation  =  expression

The assignment statement is basically two actions. First the computer has to determine the value for the expression which can be any "legal" combination of literals, variables, and operations on (pairs of) variables. Once the value is determined the second action can occur—it is copied into/stored in the memoryLocation for later use.

We typically do not read the assignment statement using the word "equals". Rather we use "becomes" or "takes the value of" or other similar word/phrase. An example shows why. We will often use code similar to count = count + 1. Clearly count cannot be "equal to" count + 1. I may forget and use "equals" sometimes but it is really important that you know, understand, and think correctly about the action of the assignment statement. It is "the" most fundamental action in programming.

Variables will be defined by the programmer (typically) with a Dim statement which will provide the name of variable and the kind of data that it can store. Properties belong to the form or form element and they are defined by the language. You can identify them by looking at the property list of a form or a control. A common property that can receive a value is the .Text property of text boxes and other controls. Expressions are combinations of literals, variables, functions, control properties, and operators. The declaration and assignment statements below illustrate these ideas.

Remember, your job is to understand this stuff and to ask questions when you don't understand. Questions? Wonderings? Comments?

	Dim intVal As Integer	'declare a variable to store whole numbers
	Dim fracVal As Double	'declare a variable to store a number with a fractional part
	Dim strVal As String	'declare a variable to store letters, digits, & special characters
				'literals as the expression
	intVal = 1
	fracVal = 1.5
	strVal = "1"
				'literals and operators
	intVal = 10 - 2 * 5     ' 0 is stored
	intVal = 10 / 5 + 2     ' 4 is stored
	intVal = 10 / (5 + 2)   ' 1 is stored Do you know why?
	intVal = 10 ^ (1/2)     ' 3 is stored Do you know why?
	intVal = 10 Mod 3       ' 1 is stored Do you know why?
	strVal = "two" & "2"    ' two2 is stored

The computer has rules for the order in which the operators are applied:

If you have a unary minus or plus in an expression (e.g., -5 + 7) it will get applied before any of the other operations. You will need to be sure you understand how expressions get evaluated.

Variables could occur in any of the places we had literals in the examples above. A similar thing happens. The values stored in the variables are looked up and placed where the variable name occurs. Then the expression is evaluated as if the values were literals.

Questions? Wonderings? Comments?

Getting Data

There are essentially two ways to accept input (get data from the user). They can type data into a text box or they can enter data via an InputBox(). Both are shown below.

Questions? Wonderings? Comments?

Functions

You are probably familiar with function from your use of calculators. For instance, most calculators have a square root function. Many have other functions. Calculator functions perform set of calculations to determine a value and then return that value. VB has a lot of functions. (You can look them up if you want.) I think the practice exercises (and your project) will use many of the following (but perhaps not many more).

Unit II Practice/Learning Activity

Unit II is about learning the basic actions of a program. Those actions are input, process, and output. In VB input typically occurs as people enter something in a text box, or click or some control. Processing will be taking the input (or finding out what was clicked on), doing something, and then producing output. Output in VB will often be putting a value into a text box or showing something in a message box. Let's look at the Unit II stuff to demonstrate some of this.

The Unit II practice activity is available on the course site via http://www.cs.uni.edu/~east/teaching/vb/current/unit-II_practice.html. We worked on a VB project that includes forms you can use to write your code. I compressed the project I made and it is available in the notes directory. You'll need to download and unzip the file (VB-practice_II.zip), then find and start the project. Any questions on doing that?

(Once everyone seems ready)

Next Time

Day 6 — Unit II Practice

Logistics

Students work on Unit II practice activity

Next Time

  • Questions? Wonderings? Comments?
  • Day 7 — Unit II Questions; Unit I Comp.Demo

    Logistics

    Questions RE Unit I

    Respond to any student questions over Unit I. Remind them that its Comp.Demo will start at approximately 4:00pm.

    Questions RE Unit II

    Respond to any student questions over Unit II.

    Competency Demonstration for Unit I

    Questions? Wonderings? Comments?

    Next Time

  • Questions? Wonderings? Comments? See you Thursday.