80 likes | 173 Views
Visual Basic: Week 5. Review User defined functions Busy wait versus Timers Homework: read chapter 4. Acquire images for ‘cards’. Will work on Memory in class. Review. Visual Basic development includes Placing controls on the form Textbox, label, command button, list box, image control
E N D
Visual Basic: Week 5 Review User defined functions Busy wait versus Timers Homework: read chapter 4. Acquire images for ‘cards’. Will work on Memory in class.
Review • Visual Basic development includes • Placing controls on the form • Textbox, label, command button, list box, image control • Control arrays of any type control • Writing code for event procedures • Form_Load, command button Click, list box Click
Code • Assignment statements target = expression • If/Then/Else • Select Case • For/Next
Built-in functions • Int • Randomize, Rnd • Str • Val • Format
Event procedures • Also known as event handlers • Visual Basic defines them. • Defines the header. • Visual Basic invokes them when an event happens. • You write the code to do something—what you want to happen when a specific event occurs. • You write the code in the code window, which you get to by double clicking on the specific control.
Controls • Each control type has its own set of properties • All control types have (name) • Many have position properties: • Left, Top • Form, command button and Label have Caption • Textbox has Text (can be changed by player) • Command button (also Timer) has Enabled. • Many have Visible. • Image has Picture. • Properties can be changed at Design time and by code during Run time.
Control array event procedure Suppose lblCards is an array of label controls The event procedure for clicking on any of the elements of the control array is Sub lblCards_Click(Index as Integer) Where Index will hold the index for the specific element clicked. You use Index in your code. For example, you will use this in Memory.
Creating a User-Defined Procedure • A user defined procedure is one in which you define (author) the header as well as write the code. • User defined procedures can be functions or subroutines, meaning they can return values or not. Call setupcards If hittarget(x,y) then • You write the user defined procedure in the code window.