Download presentation
Presentation is loading. Please wait.
Published byJordan Small Modified over 9 years ago
1
Visual Basic CODE
2
Basics of Code Declaration Declaration Set aside a named place to put things Set aside a named place to put things Assignment Assignment Put things in a named place Put things in a named place Control Control Interrupt the “top-to-bottom” flow of the program Interrupt the “top-to-bottom” flow of the program Subroutines and Functions Subroutines and Functions Write code once and invoke it from many places Write code once and invoke it from many places
3
Declaration Declares a space (like a mailbox slot) for storage of data. Declares a space (like a mailbox slot) for storage of data. Specify the name of the variable, and the type it is. For now, consider types of Integer, Boolean, String, Single/Double. Specify the name of the variable, and the type it is. For now, consider types of Integer, Boolean, String, Single/Double. Syntax: DIM name AS type Syntax: DIM name AS type DIM lastButton AS Integer DIM myResponse AS String
4
Assignment Assign a value or expression to a storage place. Assign a value or expression to a storage place. The storage place can be a simple variable, or a property of a control. The storage place can be a simple variable, or a property of a control. Variable = expression Variable = expression command1.visible = False lastButton = 2 Matches = (lastButton = 1) AND (thisButton <> 0)
5
Control Program normally proceeds from line to line. Program normally proceeds from line to line. Control statements cause other parts of code to run. Control statements cause other parts of code to run. IF expression THEN code to run if ‘expression’ not 0 ELSE code to run if ‘expression’ is 0 END IF
6
Control Example: IF lastButton <> 0 THEN command1.Visible = False command1.Visible = False END IF IF lastButton THEN thisButton = lastButton ELSE command1.caption = “First Pressed” END IF
7
Control Other control mechanisms Other control mechanisms FOR variable = startVal TO endVal NEXT variable DO WHILE expression LOOPDO LOOP WHILE expression DO LOOP UNTIL expression
8
‘Sub’ routines Put several lines of code in a ‘sub’ and then you can execute all of that code with one line: Put several lines of code in a ‘sub’ and then you can execute all of that code with one line: Sub MySub() Sub MySub() Command1.Picture = LoadPicture(“”) Command2.Picture = LoadPicture(“”) Command3.Picture = LoadPicture(“”) End Sub End Sub Private Sub Command1_Click() call MySub call MySub End Sub
9
Functions Subroutines that return a value. Subroutines that return a value. Public Function YtoM(Y AS Single) AS Single YtoM = Y * 0.9 YtoM = Y * 0.9 End Function … Yards = 10 Yards = YtoM(Yards)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.