Presentation is loading. Please wait.

Presentation is loading. Please wait.

Practical Programming COMP153-08S Week 4: Recap, Accessing Files, Menus.

Similar presentations


Presentation on theme: "Practical Programming COMP153-08S Week 4: Recap, Accessing Files, Menus."— Presentation transcript:

1 Practical Programming COMP153-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 Leaving messages –Beside your computer information just for you –On your refrigerator Share with small group –University Noticeboard Share information with Uni students & staff Recap - scope

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 1.Exponential e.g. 2 3 2.Negation e.g. − -3 3.Multiplication and Division, e.g. C * A, A / C 4.Integer Division (just returns an integer) e.g. \ 5.Modulus arithmetic (just returns remainder) e.g. Mod 6.Addition and Subtraction 7.Concatenation (the joining of strings) e.g. “Te” & “ ” & “Taka” 8.Equal to, greater than etc e.g. =, >,, <> 9.Not 10.And, AndAlso 11.Or, OrElse 12.Xor Arithmetic, comparison & logical operators

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 Count out the 100 sit-ups –For NumberOfSitups = 1 to 100 [Step 1] do the situp Next NumberOfSitups While you have energy do sit-ups –Do While Energy = good do the situp Loop Do sit-ups until you are exhausted –Do do the situp Loop Until Energy = exhausted Recap - Repetition Structure

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

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

26 Why Use Menus? Space Constrictions Consistency, Clarity, Ease of Use Speed

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

28 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

29 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

30 THE END of the lecture


Download ppt "Practical Programming COMP153-08S Week 4: Recap, Accessing Files, Menus."

Similar presentations


Ads by Google