1 / 20

Programming VB: ‘basics’

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. Variables. Variables ‘hold’ (are associated with) values Values come in different datatypes

kstayton
Télécharger la présentation

Programming VB: ‘basics’

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. 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 MAT 1420.20 Meyer Week 2

  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) MAT 1420.20 Meyer Week 2

  3. 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. MAT 1420.20 Meyer Week 2

  4. 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 MAT 1420.20 Meyer Week 2

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

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

  7. 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. MAT 1420.20 Meyer Week 2

  8. 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. MAT 1420.20 Meyer Week 2

  9. 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) MAT 1420.20 Meyer Week 2

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

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

  12. 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 MAT 1420.20 Meyer Week 2

  13. 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 MAT 1420.20 Meyer Week 2

  14. 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 MAT 1420.20 Meyer Week 2

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

  16. 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? MAT 1420.20 Meyer Week 2

  17. 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 MAT 1420.20 Meyer Week 2

  18. 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 MAT 1420.20 Meyer Week 2

  19. 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 MAT 1420.20 Meyer Week 2

  20. 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 MAT 1420.20 Meyer Week 2

More Related