Presentation is loading. Please wait.

Presentation is loading. Please wait.

MAT 1420.20 Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.

Similar presentations


Presentation on theme: "MAT 1420.20 Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read."— Presentation transcript:

1 MAT 1420.20 Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read chapter 2 Paint Shop Pro Work on mix & match

2 MAT 1420.20 Meyer Week 2 Variables Variables ‘hold’ (are associated with) values Values come in different datatypes –Integer (whole numbers, positive or negative) –Single (can have fractions) –String (sequence of characters) Unlimited or fixed size –Boolean (logical value = True or False)

3 MAT 1420.20 Meyer Week 2 Datatype conversion Visual Basic will sometimes do this for you, but good practice is to do it explicitly Strings in textboxes representing numbers must be converted to numbers in order to do arithmetic –Val(‘12’) => the number 12 and numbers must be converted to strings to be displayed –Str(12) => the string ‘12’ –Format(12.3333, “currency”) => “$12.33” Other possibilities for second parameter of Format. See HELP.

4 MAT 1420.20 Meyer Week 2 Control objects are objects placed on Forms have properties (set or allowed to be default at design time and queried & changed during run time) have pre-defined events. During design time, you write code = event procedure = event handler for certain events

5 MAT 1420.20 Meyer Week 2 Labels & Textboxes What are these and what is the difference? How are they used in rock-paper-scissors?

6 MAT 1420.20 Meyer Week 2 Command buttons Has caption property Has Click event Note: certain other control objects can have Click event procedures. Give examples from rock-paper-scissors

7 MAT 1420.20 Meyer Week 2 Names Computer Science is the field when people talk about the thing versus the name of the thing. A textbox has –(name) as the first property –text property: the current contents of the textbox. A label has –(name) as the first property –caption property: what you see in/on the label (changeable by code but not the player) A command button has –(name) as the first property –caption property: what you see in/on the label (code can change this, but untypical) An image control has –(name) as the first property –picture property: set by specifying an image file created outside VB.

8 MAT 1420.20 Meyer Week 2 Control arrays Sets of controls with the same name. Each one has its own index. Indexing starts with zero. Control array of textboxes, labels, image controls, etc. Will be used in mix & match for the sets of choices for body parts, chance for the die faces, memory for the cards. May be in different or the same location on the Form.

9 MAT 1420.20 Meyer Week 2 Array variables Internal array You can specify the bounds: –Dim strDays (1 to 7) as String 7 strings. The third one is strDays(3) –Dim sinCosts (0 to 5) as Single 6 numbers. The third one is sinCosts(2) –Dim intTable (1 to 10, 1 to 3) as Integer 10 times 3 = 30 integers. The one in the second row, third column is intTable(2,3)

10 MAT 1420.20 Meyer Week 2 Statements are the action = what gets done Give example of a statement from –The Hello, World programs –Rock paper scissors

11 MAT 1420.20 Meyer Week 2 Events Give examples of events from rock-paper- scissors

12 MAT 1420.20 Meyer Week 2 List box control Type of control Used to allow player/user to specify items in a list The items are set at run time, for example, as part of Form_Load The critical property is listindex and the critical event is Click

13 MAT 1420.20 Meyer Week 2 Image or picture control Each are for holding/displaying pictures Each have Picture property that you set at Design time by identifying an image file (or at runtime by using LoadPicture command) Visible property set to True or False controls if you can see the image Top and Left properties govern position on the form

14 MAT 1420.20 Meyer Week 2 For/Next statement Also known as (aka) loops Sets up repetition of a set of statements Index variable, start, stop, and, optionally specify step if it is not 1 For I = 1 to 10 … ‘ statements may or may not use I Next I

15 MAT 1420.20 Meyer Week 2 Example sum = 0 For I = 2 to 10 step 2 sum = sum + I Next I What is sum?

16 MAT 1420.20 Meyer Week 2 Example Assume there is a control array of 5 label controls (lblSpots) all located at Left = 0, Top = 0 (where is that??) For I = 0 to 4 lblSpots.Left = I * 100 lblSpots.caption = str(I) Next I What would this do?

17 MAT 1420.20 Meyer Week 2 Debugging Programs do not always work the first time… Debugging refers to the process of testing and refining programs. Many errors are ‘caught’ when code is written or in the initial translation stages, but some errors are not. Debugging tools include: Break, Breakpoints, Immediate window

18 MAT 1420.20 Meyer Week 2 Mix & Match cartoons Implements the book in which you can choose a hat, head, body and shoes/feet Requires sets of image files that are the body parts. List box for each body part Control array of images for each body part Listbox items will correspond to elements of the appropriate body part control array

19 MAT 1420.20 Meyer Week 2 Parallel structures Common programming technique is to have array or list structures and have correspondence between items. List box for hats: –“floppy” –“tall” Control array: imgHats –imgHats(0) has picture property floppy.bmp –imgHats(1) has picture property tall.bmp

20 MAT 1420.20 Meyer Week 2 Assignment Read chapter 2 Next class: –Paint Shop Pro lesson –Time to create your own images (Photo Shop okay & ‘acquiring’ images okay) –Work on Mix & match cartoons in lab


Download ppt "MAT 1420.20 Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read."

Similar presentations


Ads by Google