1 / 30

Practical Programming COMP153-08S

Practical Programming COMP153-08S. Week 4: Recap, Accessing Files, Menus. A Recap on the first 4 weeks. What is a control? What is a property? What is an event? How is data stored in our programs? Why do we have different data types?. Recap – storage locations. Recap - scope.

lexi
Download Presentation

Practical Programming COMP153-08S

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. Practical ProgrammingCOMP153-08S Week 4: Recap, Accessing Files, Menus

  2. A Recap on the first 4 weeks • What is a control? • What is a property? • What is an event? • How is data stored in our programs? • Why do we have different data types?

  3. Recap – storage locations

  4. Recap - scope Leaving messages • Beside your computer • information just for you • On your refrigerator • Share with small group • University Noticeboard • Share information with Uni students & staff

  5. Scope in VB programming Local variable • Beside your computer • For use only inside one procedure • Use Dim to declare Form-level variable • the flat fridge • For use by more than one procedure • Use Private to declare • Declare at top of form

  6. Recap - Control Structures There are 3 main control structures in programming • Sequence • Selection (choice) • Iteration (repeating)

  7. Recap - Sequence • Default control structure • One commend follows another

  8. Recap - Selection • Condition  Action

  9. Recap - Selection But sometimes expressions can be ambiguous Son, please go to the shop and buy us 4 apples and 3 pears or 3 bananas In English we can use higher-level knowledge, pauses in speech, intonation, etc… • How can we do this in programming? By defining Rules of Precedence…

  10. Arithmetic, comparison & logical operators • Exponential e.g. 23 • Negation e.g. − -3 • Multiplication and Division, e.g. C * A , A / C • Integer Division (just returns an integer) e.g. \ • Modulus arithmetic (just returns remainder) e.g. Mod • Addition and Subtraction • Concatenation (the joining of strings) e.g. “Te” & “ ” & “Taka” • Equal to, greater than etc e.g. =, >, <, =<, =>, <> • Not • And, AndAlso • Or, OrElse • Xor

  11. Recap - IF Selection Structure

  12. Recap - IF/Else IF Selection Structure

  13. Recap - Case Selection Structure

  14. Which Selection Structure is Best? • 2 statements… • If condition THEN action1 Else action2 …EndIf • Select Case expression …End Select • Use the If Selection Structure when the expression has only 1 or a small number of possible outcomes • Use the Case Selection Structure to handle many outcomes requiring different actions for each value…

  15. Recap - Repetition • To prepare the pancakes sift the flour and baking powder into a large bowl. Make a well in the centre. Combine the first egg, milk and oil and stir into the flour. Repeat this for second egg.Mix until a smooth batter is formed, then pour into a jug. Brush a heated pancake tin with oil. Pour in enough of the batter to thinly cover the base of the pan. Cook for 2-3 minutes until the mixture sets. Turn over using a metal spatula and cook for a further 1-2 minutes. Remove and place on a plate and cover with a square of greaseproof paper. Continue until all the batter has been used. Keep the pancakes warm.

  16. Two Types of Loops • Counter Controlled • Performs the loop for a certain count • Sentinel Controlled • Keep looping until a value or set of values is reached

  17. Recap - Repetition Structure For counter = start To end [Step value] [actions] Next counter Do While|Until condition (Pre-test) [actions] Loop Do [actions] Loop While|Until condition (Post-test)

  18. Recap - Repetition Structure • Count out the 100 sit-ups • For NumberOfSitups = 1 to 100 [Step 1] do the situpNext NumberOfSitups • While you have energy do sit-ups • Do While Energy = good do the situpLoop • Do sit-ups until you are exhausted • Do do the situpLoop Until Energy = exhausted

  19. Memory Currently we have used variables and form controls to store information What if we want to access some information after the program has shut down? What if we want to share the information with other programs, or other users?

  20. Using Files to Store Information • Computer Programs typical use 3 types of files • Sequential Access Files • Random Access Files • Binary Access Files

  21. Sequential Access

  22. Sequential Access

  23. Random Access

  24. Sequential Access Files • Information is stored serially, or in sequence • Must be accessed from start to finish • Information is usually stored as text, hence often called text files • Three separate processes • Reading from a file • Writing to a file • Appending to a file

  25. Why Use Menus? • Space Constrictions • Consistency, Clarity, Ease of Use • Speed

  26. Adding Menus to the interface • Locate the MainMenu Control from the toolbox and drag it onto the form • Click on Type Here and type in the name of the first menu • Add further Menu Items underneath and to the side of the first menu item • Adjust the text properties of the Menu Items • Create sub procedures that are activated by the Menu Items

  27. Access Keys • These allow commands to be entered without using the mouse • Very simple to code • Place an & symbol in the text property of the button • Very simple to use • Alt + letter

  28. Shortcut Keys • These are similar to access keys but are used in menu items • Very simple to code • In the Short Cut property of the Menu Item select the Shortcut Sequence • Best to select Ctl and a letter • Very simple to use • Clt + letter

  29. THE END of the lecture

More Related