|
Morning Announcements & Pledge
Spring Break Week in
|
|
|
Click for Instructions
Click on the date to open the details.
Click date again to close the details.
|
| Day |
Date |
|
Discussion
|
|
09/03/07 |
|
Monday - Labor Day Holiday
--
Send your e-mail address to Mr. Clarke before school starts
asking for Extra Credit & receive Extra Credit!!!
Send your parent's/guardian's e-mail address e-mail to Mr. Clarke before school starts
and receive Extra Extra Credit!!! |
|
09/04/07 |
|
Tuesday -
OCVTS School Closed - Teacher's Preparation Day |
| 1 |
09/05/07 |
|
Wednesday - Classroom Rules - Welcome
to Computer Science |
|
- Classroom Discussion -
- Distribute student "css##" ID numbers &
passwords
- Test ID numbers & passwords by logging on
- Setup printers for use, instructions in "Lab Assignment" below
- Discuss School Rules
using Microsoft PowerPoint presentation, click link
- Lab Assignment -
- Review classroom rules
- Forms to complete & return to teacher:
- Message from Principal - student signature
- Emergency Card - student fills out
- Computer Contract - student & parent/guardian signatures
- Social Security Number - student signature
- Consent Form - parent/guardian signature
- Research "History of Computing" online, take
notes, bookmark the best sites, & be prepared to participate in
classroom discussion tomorrow
- Contact information - send "mclarke@mail.ocvts.org" an e-mail from
your e-mail address
- AIM contact name - "compSciClarke"
- Microsoft IM contact - "mrclarke@hotmail.com"
- Guidelines to Add New Printer:
- Click "Start"
- Click "Printers & other hardware"
- Identify any existing printers (HP LJ5) &
(Tektronix)
- If they both exist, simply close the
printers window, otherwise, continue:
- Click "Add a Printer" to open the Printer
Wizard
- Read the Welcome Message & Click "Next"
- Our printers are Network Printers, click
that button, & click "Next"
- Search for printers
- Click "HP LJ5" & click "Next"
- Click "Finish" to add the printer
Repeat for the "Tektronix" printer
|
| 2 |
09/06/07 |
|
Thursday - Classroom Rules, Computer
IDs, & History of Computing Science |
|
- Classroom Discussion -
- Distribute student "css##" ID numbers &
passwords
- Test ID numbers & passwords by logging on
- Setup printers for use, instructions in "Lab Assignment" below
- Discuss School Rules
using Microsoft PowerPoint presentation, click link
- Discuss The History of Computing Science
- Lab Assignment -
- Review classroom rules
- Forms to complete & return to teacher:
- Message from Principal - student signature
- Emergency Card - student fills out
- Computer Contract - student &
parent/guardian signatures
- Social Security Number - student signature
- Consent Form - parent/guardian signature
- Research "History of Software" online, take
notes, bookmark the best sites, & be prepared to participate in
classroom discussion tomorrow
- Contact information - send "mclarke@mail.ocvts.org" an e-mail from your
e-mail address
- AIM contact name - "compSciClarke"
- Microsoft IM contact - "mrclarke@hotmail.com"
|
| 3 |
09/07/07 |
|
Friday - Classroom Rules, History of
Software, Intro to Visual Basic, "vbHelloWorld" |
|
- Classroom Discussion -
- Distribute student "css##" ID numbers &
passwords
- Test ID numbers & passwords by logging on
- Setup printers for use, instructions in "Lab Assignment" below
- Discuss School Rules
using Microsoft PowerPoint presentation, click link
- Discuss History of Software:
- Computer System:
- Hardware: System Box, Keyboard, Mouse,
Monitor, Printer, etc.
- Software: Operating System &
Applications Software
- People: Requried to input data &
receive output information
- Data: Facts & Figures
- Computer System does four things:
- Input: Information put into a
communications system for transmission or into a computer system
for processing: Keyboard & Mouse
- Process: A part of a running software
program or other computing operation that does a single task
- Storage: The part of a computer that
stores information for subsequent use or retrieval: Hard Disk,
Floppy Disk, Memory Stick, Optical Disk
- Output: The information produced by a
program or process from a specific input: Monitor, Printer
- Two types of software:
- Operating Systems: Software designed to
control the hardware of a specific data-processing system in order
to allow users & application programs to make use of it
- Applications Software: a program that
gives a computer instructions that provide the user with tools to
accomplish a task
- Operating Systems:
- MS-DOS: Microsoft Disk Operating System
- Windows: A rectangular area on the screen
that displays its own file or message independently of the other
areas of the screen
- Apple OS: Apple Computer Corporation
Operating System
- Unix: An interactive time-sharing
operating system invented in 1969
- Linux: An implementation of the Unix
kernel originally written from scratch with no proprietary code
- Applications Software:
- Word Processing: The creation, input,
editing, & production of documents & texts by means of
computer systems
- Spreadsheet: An accounting or bookkeeping
program that displays data in rows & columns on a screen
- Database: Programs to ease the collection
of data arranged for ease & speed of search & retrieval
- Presentation: Software program for
creating graphic presentations with visual aids, handouts, slides,
etc
- Entertainment: Software that amuses,
pleases, or diverts
- Education: Software whereby knowledge or
skill is obtained or developed by a learning process
- Communications: Software for sending &
receiving messages
- Software Developers use Programming
Languages to create both Operating Systems & Applications
Software:
- Source Code: Before interpreting or
compiling: Code written by a programmer in a high-level language
& readable by people but not computers. Source code must be
converted to object code or machine language before a computer can
read or execute the program
- Machine Code: After interpreting or
compiling: The code produced by a compiler from the source code,
usually in the form of machine language that a computer can
execute directly
- Two main types of programming languages:
- Interpreter: A program that translates an
instruction into a machine language & executes it before
proceeding to the next instruction
- Compiler: A program that translates
another program written in a high-level language into machine
language so that it can be executed
- Basic is an interpreted language. Visual
Basic may also be compiled into executable code.
- The History of Programming
- History's Worst Software Bugs
- Introduction to Visual Basic:
- Different ways to open the VB IDE in Windows
- VB IDE - Integrated Development Environment
- Menu Options & Features
- Toolbox, Project, & Properties Windows
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 in 24 Hours
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 1 - Visual Basic at Work
- Lab Assignment -
- Review classroom rules
- Find your network home drive:
- Open Windows Explorer - click [start], click [my computer]
- Navigate to your home drive - letter "H:"
- Review the folders available
- Let me know if you have any problems
- Create a Visual Basic program "HelloWorld":
- Save your work to your "My Documents" folder
- You don't have "write" permissions to the VB6 folder
- You share the PC with another student
- You won't "overwrite" another student's work
- Another student won't "overwrite" your work
- Make a new folder in your "My Documents" called "Hello World" & save all your "Hello World" work there
- Open VB & create a new, standard.exe
- Save the form as "frmHelloWorld.frm"
- Save the project as "vbHelloWorld.vbp", both into your "My
Documents/vb" folder
- Name the Form "frmHelloWorld"
- Change the Form caption to "My First VB Program"
- Change the Form background color as desired
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- Add a Textbox object & name it "txtHelloWorld"
- Change the Textbox text property to "Hello World!"
- Change the Textbox font sizes as desired
- Change the Textbox size as necessary
- Change the Textbox background & foreground colors
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- Add a Label object & name it "lblHelloWorld"
- Change the Label caption property to "Hello World!"
- Change the Label font sizes as desired
- Change the Label size as necessary
- Change the Label background & foreground colors
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- Add a Command Button object & name it "cmdHelloWorld"
- Change the Command Button caption property to "Hello World!"
- Change the Command Button font sizes as desired
- Change the Command Button size as necessary
- Change the Command Button background & foreground colors (is there a foreground color?)
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- To open an existing VB6 project:
- Open Windows Explorer
- Navigate to the correct folder
- Double click on the ".vbp" file
- Research "Word Processing" & "Microsoft Word
Tutorial" online, take notes, bookmark the best sites, & be prepared
to participate in classroom discussion Monday
- Forms to complete & return to teacher:
- Message from Principal - student signature
- Emergency Card - student fills out
- Computer Contract - student &
parent/guardian signatures
- Social Security Number - student signature
- Consent Form - parent/guardian signature
- Contact information - send "mclarke@mail.ocvts.org" an e-mail from your
e-mail address
- AIM contact name - "compSciClarke"
- Microsoft IM contact - "mrclarke@hotmail.com"
|
|
| 4 |
09/10/07 |
|
Monday - Visual Basic Label, Textbox, & CommandButton objects, "vbAge" |
|
- Classroom Discussion -
- Some Definitions:
- Program: A sequence of instructions that a
computer can interpret & execute
- Programming: Creating a sequence of
instructions to enable the computer to do something
- Systems Analysis: The study of an activity
or procedure to determine the desired end & the most efficient
method of obtaining this end
- Writing a good program is the act of taking
a large problem & continually splitting it into smaller &
smaller sub-problems until you reach a point where each sub-problem
requires one solution & is easy to program
- Three types of sub-programs:
- sub-procedures
- sub-routines
- functions
- Syntax: The rules governing the formation of
statements in a programming language. Every programming language has
similar, but different, syntax rules
- Computer Error: the occurrence of an
incorrect result produced by a computer
- Three types of computer error:
- Syntax Error: an error in a program due to
a code that does not conform to order expected by the programming
language, detected during compiling or interpreting
- Run-Time Error: an error in arithmetic
during computer run that, detected at run time
- Logic Error: an error the programmer
makes during design of the program, the program compiles & runs
but gives incorrect results
- Computer User: A person who uses computers
for work or entertainment or communication or business
- Most users lack full understanding of how to truly use a computer
- Some users are actually afraid of the computer
- All users are either slow to learn or understand; obtuse or tend to make poor decisions or careless mistakes
- Therefore, it is up to the programmer to make the program as "idiot-proof" as humanly possible
- Users are [insert appropriate word here]!!!
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 2 - Analyzing Visual Basic Programs
Lab Assignment -
- School Rules Quiz
- Click the link & follow the instructions
- Principal Coleman requires that each student score 100% on this quiz
- You will continue to take the quiz each day until you score 100%
- Create a Visual Basic program "Age":
- Open VB & create a new, standard.exe
- Save the form as "frmAge.frm" & save the project as "vbAge.vbp", both into your "My Documents/vb" folder
- Name the form "frmAge", change the caption to "Given your age, calculate your year of birth"
- Add a Label object, name it "lblTitle", change the caption property to "Instructions: Enter your age in the age box & click GO to calculate your year of birth"
- Add a Label object, name it "lblAge", change the caption property to "Your Current Age", this will identify what the user is to enter into the textbox
- Add a Label object, name it "lblYear", change the caption property to "Year of Birth", this will identify the answer
- Add a Textbox object, name it "txtAge", change the text property to "", this is where the user will enter his age
- Add a Label object, name it "lblAnswer", change the caption property to "", this will hold the answer
- Add a CommandButton object, name it "cmdCalculate", change the caption property to "&Calculate", change the default property to "True"
- Add a CommandButton object, name it "cmdExit", change the caption property to "e&Xit", change the cancel property to "True"
- Double-click the CommandButton object "cmdExit" & enter "End". This program instruction, executed through a user click event, will cause the program to stop running
- Double-click the CommandButton object "cmdCalculate" & enter "lblAnswer.Caption = 2007 - txtAge.Text". This program instruction, executed through a user click event, will change the Textbox object "txtYear" "Text" property to be the result of the process of subtracting the user's age, found in the Textbox object "txtAge" "Text" property, from the year 2007
- Center the instructions across the top of the form
- Change font sizes as desired
- Change background & foreground colors
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- - Figure out how to add objects to allow the user to enter his year of birth and display his age
|
| 5 |
09/11/07 |
|
Tuesday - Putting Code into Visual
Basic, Image Object, "vbTrafficLight" |
|
- Classroom Discussion -
- Discuss the Image object & it's properties
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 18 - The Graphic Image Controls
Lab Assignment -
- School Rules Quiz
- Click the link & follow the instructions
- Principal Coleman requires that each student score 100% on this quiz
- You will continue to take the quiz each day until you score 100%
- Create a simple VB program to display a
traffic light image. Provide the user with three command buttons
"Stop", "Caution", & "Go". These buttons will control which of three
images will display in the form on the screen:
- Use Microsoft Paint to create three image files called "Stop.bmp", Caution.bmp", "Go.bmp"
- Alternatively, you may locate three images I found on the Internet: Look on the "Q:" drive for files named "traffic_light_green.jpg", "traffic_light_red.jpg", & "traffic_light_yellow.jpg"
- Save these to your "My Documents/vb" folder
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" in a new folder called "light" as "light.frm" & "light.vbp"
- VB will NOT correctly locate any images until you close & reopen it:
- Save
- Close Visual Basic
- Use Windows Explorer (My Computer or My Documents) to navigate to your "My Documents/vb/light/" folder
- The images & VB files should all be stored in the same folder
- Open VB by double-clicking on the "light.vbp" file
- Name the form "frmLight"
- Add an image object to the center of your
form
- Name the image object "imgLight"
- Change the size to make it twice as high as
it is wide
- Add a command button.
- Name the command button "cmdRed"
- Change the caption to read "Red"
- Double-Click the "cmdRed" command button
to open the code window
- Add this line: "imgLight.Picture =
LoadPicture("traffic_light_red.jpg")"
- Save all your work & images in the same folder
- Add another command button for "Yellow",
change the name, change the caption, add the code
- Add another command button for "Green", change
the name, change the caption, add the code
- Add a label named "lblInstructions" with a
caption instructing the user to press the buttons to see the light
change
- Add another command button for "Exit"
- Name the Command Button "cmdExit"
- Change the Command Button caption to
"e&Xit"
- Change the Cancel property to "True" for
the excape key
- Double-Click the Command Button to open the
Code Window
- Add "End" after the subroutine title
cmdExit_Click() line & before the End Sub line
- Use menu bar options "Run", "Start" to test
your program
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance)
- - Figure out how to display the light image "traffic_light_all.jpg" when the program starts before the user presses any buttons
- - Figure out how add control objects to allow the user to clear or remove the traffic light totally from the screen so the user sees nothing
|
| 6 |
09/12/07 |
|
Wednesday - Visual Basic Practice with
Image, Label, Textbox, & Command Button Objects, "vbImageDisplayer",
"vbTextDemo", "vbRailDemo" |
|
- Classroom Discussion -
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 3 - Controls and Properties
Lab Assignment -
- School Rules Quiz
- Click the link & follow the instructions
- Principal Coleman requires that each student score 100% on this quiz
- Students who have not achieved 100% will take the quiz again
- Create a simple VB program to display images two ways, normal & stretched:
- Windows contains a large number of bitmap & other graphics files
- Use a text box into which the user enters the name of a graphical image
- When the user clicks a command button, display the selected graphics file in two Image objects
Some ideas:
- Open VB & create a new, standard.exe
- Make a folder "imageDisplayer"
- Save as "frmImageDisplayer.frm" & "vbImageDisplayer.vbp" to your "My Documents/VB/imageDisplayer" folder
- Rename the Form to "frmDisplayer"
- Resize the Form to about twice as wide as it is high
- Change the caption property to read "John Doe's Famous Image Displayer", but use your name
- Add a Label object named "lblImageFileName" & change the caption property to something like "Enter File Name:"
- Add a Textbox object named "txtImageFileName" & change the text property to be blank
- Add two Image objects, the first on the left, the second on the right
- Name the first Image object "imgLeft" & the second "imgRight"
- Make both Image objects the same size & large
- Change the stretch property for imgRight to "True"
- Add a Command Button object named "cmdDisplay" & change the caption property to "&Display"
- Set this Command Button to run when the "Enter" key is pressed
- Double click the "cmdDisplay" command button & add these lines to the code window:
"imgLeft.Picture = LoadPicture(txtImageFileName.Text)"
"imgRight.Picture = LoadPicture(txtImageFileName.Text)"
Your names must match my names for this code to work
- Add a Command Button object named "cmdExit" & change the caption property to "e&Xxit"
- Set this Command Button object to run when the "Escape" key is pressed
- Write the code for the "Exit" button
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance)
- SAVE FREQUENTLY
- Figure out how to make the text window a dropdown menu with all the images in a folder listed
- Create a VB program to demonstrate how text can be moved to different control instances on a form:
- When the user clicks on button 1, copy the caption from button 1 to the caption of label 1 & the text of text box 1
- When the user clicks on button 2, copy the caption from label 2 to the text of text box 2
- When the user clicks on button 3, copy the
text from text box 3 to the caption of label 3
Some ideas:
- Open VB & create a new, standard.exe
- Make a folder "textDemo"
- Save to your "My Documents/vb/textDemo" folder as
"frmTextDemo.frm" & "vbTextDemo.vbp"
- Create a form with three labels, three text
boxes, & three command buttons
- Name the form "frmTextDemo"
- Arrange the objects so they look good
- Name the form "frmTextDemo" & change the
caption to something appropriate
- Name the first text box "txt1" & change
the text to read "Text Box 1"
- Name the second text box "txt2" & change
the text to read "Text Box 2"
- Name the third text box "txt3" & change
the text to read "Text Box 3"
- Name the first label "lbl1" & change the
caption to read "Label 1"
- Name the second label "lbl2" & change the
caption to read "Label 2"
- Name the third label "lbl3" & change the
caption to read "Label 3"
- Name the first command button "cmd1" &
change the caption to read "Button 1"
- Name the second command button "cmd2" &
change the caption to read "Button 2"
- Name the third command button "cmd3" &
change the caption to read "Button 3"
- Double click the first command button &
add this code:
lbl1.Caption = cmd1.Caption
txt1.Text = cmd1.Caption
- Double click the second command button &
add this code:
txt2.Text = lbl2.Caption
- Double click the third command button &
add this code:
lbl3.Caption = txt3.Text
- Add an Exit command button, change the name
& caption. Use the "&" to make a hotkey. Make it so the
"escape" key will activate the Exit event. Double click the Exit
command button & add the code to "End" the program
- Use the techniques you learned over the
past couple of days
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance)
- What would happen if
the user changed the text in text box 2 & then clicked on command
button 2? Test your thesis
- Create a VB program to simulate a railroad
train schedule:
- Design a form that would allow the user to
choose between displaying "Morning", "Afternoon", or "Evening" train
schedules
- The information to be displayed would be
"Scheduled Departure Time", "Track Number", & "Train Status"
- Leave room to display up to five trains
Some ideas:
- Open VB & create a new, standard.exe
- Create a folder "railDemo"
- Save to your "My Documents/vb/railDemo" folder as
"frmRailDemo.frm" & "vbRailDemo.vbp"
- Name the form "frmRailDemo"
- Add a Command Button object for "Exit",
write the code, make the "Escape" key work
- Math time -- you need three labels (Time,
Track, & Status) for each of five trains:
3 x 5 = 15
so, you need to add 15 Label objects. Be sure to name each one
separately, something like: lblTime1, lblTrack1, lblStatus1
lblTime2, lblTrack2, lblStatus2
lblTime3, lblTrack3, lblStatus3
lblTime4, lblTrack4, lblStatus4
lblTime5, lblTrack5, lblStatus5
Arrange them on the form so they look good.
- Make the "Border Style" property for all
Label objects "Fixed Single" so that they look like unchangable
Textbox objects
- Write the code for the "Morning" Command
Button object:
lblTime1.Caption = "7:00 a.m."
lblTrack1.Caption = "Track 2"
lblStatus1.Caption = "On Time"
lblTime2.Caption = "7:20 a.m."
lblTrack2.Caption = "Track 1"
lblStatus2.Caption = "On Time"
lblTime3.Caption = "8:00 a.m."
lblTrack3.Caption = "Track 3"
lblStatus3.Caption = "Delayed"
lblTime4.Caption = "8:30 a.m."
lblTrack4.Caption = "Track 1"
lblStatus4.Caption = "On Time"
lblTime5.Caption = "9:00 a.m."
lblTrack5.Caption = "Track 2"
lblStatus5.Caption = "On Time"
Remember that your program will only work with my code if you
use the same object names that I have
- Write similar code for the "Afternoon" &
"Evening" Command Button objects
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance)
- - Make one of the
"Afternoon" blank & have only four trains
- Your "H:" drives should now work. You may
only access your own "H:" drive. I can access all "H:" drives. Copy
your work there so I may see it:
- Open "Windows Explorer" or "My Documents"
& navigate to "H:"
- View the folders I have created:
- C++ - for the C++ programming language projects we will create
- Grades - for me to place an Excel spreadsheet with your grades, assignments completed, & assignments due
- Java - for the Java programming language projects we will create
- OtherAssignments - for other assignments
- toBeGraded - for any project that you wish me to grade - NOTE: I will empty this folder after I grade your work
- VB - for the Visual Basic programming language projects we will create
- Every
day, after your work is complete, copy the most recent folders & files to the
proper folder on the "H:" drive
- If you want me to grade an assignments, also copy it to "toBeGraded"
|
| 7 |
09/13/07 |
|
Thursday - OCVTS School Closed - Rosh Hashanah |
|
- Classroom Discussion -
- Parental/Guardian signed forms due on Monday: no computer contract = no computer
use
- Discuss Chapter 5 from Free-Ed.Net on Visual Basic,
"Lesson 5 - Putting Code into VB"
- Discuss:
- Lab Assignment -
- School Rules Quiz
- Click the link & follow the instructions
- Principal Coleman requires that each student score 100% on this quiz
- You will continue to take the quiz each day until you score 100%
- Create a simple VB program to test data type
mixups:
- Assign a real number to an integer variable
& display the integer variable in a label caption
- Assign an integer number to a real variable
& display the integer variable in a label caption
Some
ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My
Documents/vb" folder as "frmVariableDemo.frm" & "vbVariableDemo"
- Name the form
- Add code for two global variables at the
top of the code window:
Dim sngNum As Single
Dim intNum As Integer
- Add a command button & code & "cancel"
for exit
- Add a text box for input "txtInput"
- Add a label for output "lblOutput"
- Add a command button & code for
RealInteger
intNum = txtInput.Text
lblOutput.Caption = intNum
- Test with a real number, like "2.5". Is the
output real or integer?
- Add a command button & code for
IntegerReal
sngNum = txtInput.Text
lblOutput.Caption = sngNum
- Test with an integer number, like "7". Is
the output real or integer?
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance)
- What happens if you
enter a word or a date?
- Create a VB program to perform common
distance conversions:
- Inches to Centimeters
- Centimeters to Inches
- Feet to Meters
- Meters to Feet
- Miles to Kilometers
- Kilometers to Miles
For your
conversion numbers:
- 1 inch = 2.54 centimeters
- 1 centimeter = 0.4 inches
- 1 foot = 0.305 meters
- 1 meter = 3.28 feet
- 1 mile = 1.6 kilometers
- 1 kilometer = 0.625 miles
Some
ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My
Documents/vb" folder as "frmDistanceConverter.frm" &
"vbDistanceConverter"
- Add a textbox for input
- Add a label for output
- Add instructions to the user
- Add & name a command button for each
conversion
- Here's the general steps for each button:
- Assign the input text into a variable
- Calculate the answer
- Assign the answer to the output label
caption
- For example, Inches to Centimeters, if
you use these variable names:
dblInput = txtInput.text
dblOutput = dblInput * 2.54
lblOutput.caption = dblOutput
- Add a command button & code & "cancel"
for exit
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance). Use numbers that are easy to confirm. For example:
10 inches = 25.4 centimeter
10 centimeters = 4.0 inches
- Add some other useful
distance conversions
|
| 8 |
09/14/07 |
|
Friday -
"vbTemperatureConverter" |
|
- Classroom Discussion -
- Parental/Guardian signed forms due on Monday: no computer contract = no computer
use
- Next week my AM class is assigned the pledge
& morning announcements - any volunteers?
- Discuss:
- Global Variables - Declared at the top of
the program, usable by any part of the program
- Local Variables - Declared inside a
sub-routine, usable by ONLY that sub-routine
- OPTION EXPLICIT - Written as the first line
of the program, requires the programmer to correctly declare &
spell any & all variables -- a great programming technique
- Variable Naming Convention:
- Must start with a letter
- May contain letters & numbers
- May NOT contain special characters
- May contain underscore "_"
- Use the 3-letter prefix patterns:
- int for integer
- sng for single
- dbl for double
- str for string
- bln for boolean
- dtm for date
- Should make sense to another programmer:
- use intAge instead of a
- use sngPayRate instead of pr
- use dblLightSpeed instead of ls
- use strFirstName instead of fn
- use blnIsActiveMember instead of iam
- use dtmBirthDate instead of bd
- Variable Declaration Syntax - "Dim VarName
As DataType" - Examples:
- Dim intAge As Integer
- Dim sngPayRate As Single
- Dim dblLightSpeed As Double
- Dim strFirstName As String
- Dim blnIsActiveMember As Boolean
- Dim dtmBirthDate As Date
- Review before Quiz - NOW is the time to
ask your questions
- Lab Assignment -
- Create a VB program to perform common
temperature conversions:
- Fahrenheight to Centigrade
- Centigrade to Fahrenheight
For your
conversion numbers:
- Fahrenheight temperature is 9/5ths of the
Centigrade temperature plus 32 (do the plus 32 last)
- Centigrade temperature is 5/9ths of the
Fahrenheight temperature minus 32 (do the minus 32 first)
- (If you can't figure out the conversion,
watch the board, I'll do some examples)
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My
Documents/vb" folder as "frmTemperatureConverter.frm" &
"vbTemperatureConverter"
- Add a textbox for input
- Add a label for output
- Add instructions to the user
- Add variables at the top of the program
- Add & name a command button for each
conversion
- Here's the general steps for each button:
- Assign the input text into a properly
named variable of the proper data type
- Calculate the answer & assign the
answer to the output label caption
- Add a command button & code & "cancel"
for exit
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for
assistance). Use numbers that are easy to confirm. For example:
68o F = 20o C & 20o C = 68o
F 77o F =
25o C & 25o C = 77o
F 86o F =
30o C & 30o C = 86o
F
- Add some other useful
temperature conversions, like Kelvin
- Complete any unfinished labs
|
|
| 9 |
09/17/07 |
|
Monday - Pledge & Announcements, Visual Basic Quiz 1, VB Input/Output, "vbTemperatureConverter2" |
|
- Classroom Discussion -
- One AM student needed as volunteer to assist with the morning pledge & announcements
- Parental/Guardian signed forms due TODAY: no computer contract = no computer use
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 4 - Examining Labels, Buttons, and Text Boxes
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 5 - Putting Code into Visual Basic
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 6 - Message and Input Boxes
- VB Code Comments or Remarks - Remarks help both you & other programmers who might modify & update your Visual Basic applications in the future. Remarks offer descriptive messages that explain in English (or whatever language you prefer) what's going on in the program's event procedures:
REM This is one example of a remark
' This an example of a comment
Dim intAge As Integer REM This is a third example of a remark
intAge = 17 ' & this is a fourth example of a comment
Programmers often add remarks to their programs for the following purposes:
- To state the programmer's name & the date that the program was written
- To describe in the general section the overall goal of the program (the general section appears before all of a procedure's procedures & is the location Hour 5, "Putting Code into Visual Basic," described when it talked about declaring global variables)
- To describe at the top of every procedure the overall goal of that procedure
- To explain tricky or difficult statements so that others who modify the program later can understand the lines of code without having to decipher cryptic code
- VB Output - MsgBox() - Instructions or output to the user, returns a number that tells which button the user has clicked:
- Do lab 1
- VB Input - InputBox - Another way to get input, returns a string value that holds the answer typed by the user:
- Syntax:
strVariable = InputBox( strPrompt [, [strTitle] [, strDefault] [, intXpos, intYpos]]])
- strPrompt - the content of the message to the user
- strTitle - optional message box title bar text
- strDefault - optional default input so that the user can just hit [OKAY]
- intXpos - number of twips from the left side
- intYpos - number of twips from the top
- Do lab 2
- Lab Assignment -
- Visual Basic Quiz 1
- Modify your "vbTemperatureConverter.vbp" program to use a MsgBox:
- Use a MsgBox to tell the user goodbye on exit
Some ideas:
- Use windows explorer & navigate to where your program "vbTemperatureConverter.vbp" is saved & open it
- Add a new global variable at the top:
Dim intMsgRes As Integer
- View the form & double click command button exit
- Add VB code for a MsgBox before the "End" command:
intMsgRes = MsgBox("Goodbye")
- Test it to see how it works
- Modify the VB msgbox code to see how some of the icons & buttons & title work:
intMsgRes = MsgBox("Goodbye", vbInformation, "Exit Message")
or
intMsgRes = MsgBox("Goodbye", vbOKOnly, "Son of a Gun")
or
intMsgRes = MsgBox("Goodbye", vbExclamation + vbonly, "This is Fantastic")
or
intMsgRes = MsgBox("Goodbye", vbQuestion + vbYesNo, "Or maybe Tanfastic")
or
intMsgRes = MsgBox("Goodbye", vbCritical + vbAbortRetryIgnore, "I'm gettin' this")
- Modify your "vbTemperatureConverter.vbp" program to use an InputBox:
- Use an InputBox to allow the user to confirm the temperature
- Echo the user input from the textbox as the default in an InputBox & ask the user it this is accurate
Some ideas:
- View the form & double click command button FahrToCent
- Modify VB code for an InputBox after assigning the textbox to a variable but before processing the variable:
sngFahr = txtInput.Text
sngFahr = InputBox("Convert this temperature?", , sngFahr) ' confirm temperature to be converted
txtInput.Text = sngFahr ' put the inputbox temperature into the textbox in case the user has changed it
sngCent = (sngFahr - 32) * 5 / 9
lblOutput.Caption = sngCent
- Test it to see how it works
- Modify the VB msgbox code to see how the title works:
sngFahr = InputBox("Convert this temperature?", "Temperature Confirmation, sngFahr)
- Do similarly for Centigrade to Fahrenheit
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Add a confirm exit MsgBox to all of your VB programs
|
| 10 |
09/18/07 |
|
Tuesday - Pledge &Announcements, VB IF THEN Statement, "vbSalary", "vbGrades" |
|
- Classroom Discussion -
- One AM student needed as volunteer to assist with the morning pledge & announcements
- Parental/Guardian signed forms due: no computer contract = no computer use
- Vocabulary:
- Three types of statements in every programming language:
- Sequential - Following of one after another
- Decision - The act of reaching a conclusion or making up one's mind
- Iteration - To perform again; repeat
- Algebra - A branch of mathematics in which symbols, usually letters of the alphabet, represent numbers or members of a specified set & are used to represent quantities & to express general relationships that hold for all members of the set
- George Boole (1815-1864) - British mathematician & logician who developed a calculus of symbolic logic
- Boolean - Of or relating to a logical combinatorial system treating variables, such as propositions & computer logic elements, through the operators AND, OR, NOT, & XOR
- Boolean Algebra - An algebra in which elements have one of two values & the algebraic operations defined on the set are logical OR, a type of addition, & logical AND, a type of multiplication
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 7 - Making Decisions
- Review Arithmetic Operators & Order of Operations (PEMDAS):
- ( ) Parenthesis
- ^ Exponentiation
- * Multiply
- / Divide
- + Add
- - Subtract
- Review String Arithmetic Operator:
- Comparison Operators:
- > Greater Than
- < Less Than
- = Equal To
- >= Greater Than or Equal To
- <= Less Than or Equal To
- <> Not Equal To
- Comparison Rules:
- Returns True or False
- Resulting return may be stored in a Boolean variable
- Compare only two objects at a time
- Both sides must be the same data type
- Do not compare non-integer numbers for equality
- To compare three or more objects, compare pairs using Boolean operators & Boolean Algebra
- Comparison Examples:
- lblSales.Caption > Goal
- Pay < 2000.00
- Age = Limit
- FirstName >= "Mike"
- Num <= lblAmt.Caption
- txtAns.Text <> "Yes"
- The VB IF THEN Statement:
- Lab Assignment -
- Create a new VB program to process Salary:
- Receive hours worked from the user
- Receive pay rate from the user
- Calculate & display gross pay
- Calculate & display taxes
- Calculate & display net pay
Program Logic:
- User will enter hours worked & pay rate, so you need to save this data to variables
- Gross pay is calculated as hours worked times pay rate
- Taxes is calculated as 20% of gross pay
- Net pay is the result of subtracting taxes from gross pay
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "frmSalary.frm" & "vbSalary.vbp"
- Create variables at the top:
Option Explicit
Dim sngHoursWorked As Single
Dim sngPayRate As Single
Dim sngGrossPay As Single
Dim sngTaxes As Single
Dim sngNetPay As Single
Dim intMsgRes As Integer
Dim strResults As String
- Add a command button to exit, set the cancel property to true so the escape key works, add the code to end
- Modify the exit button to use a MsgBox to allow the user to confirm upon exit:
intMsgRes = MsgBox("Really Exit?", vbQuestion + vbYesNo, "Confirm Exit")
If intMsgRes = vbYes Then
End ' exit on user click yes
End If
- Add a command button to go, set the default property to true so the enter key works, add the code:
- Receive sngHoursWorked & sngPayRate from the user using InputBoxes:
sngHoursWorked = InputBox("Enter Hours Worked", "Hours Worked", 30)
sngPayRate = InputBox("Enter Pay Rate", "Pay Rate", 10)
- Calculate gross pay, taxes, & net pay:
sngGrossPay = sngHoursWorked * sngPayRate
sngTaxes = sngGrossPay * .2
sngNetPay = sngGrossPay - sngTaxes
- Display results to user using a message box:
strResults = "Hours Worked: " & sngHoursWorked & vbCrLf
strResults = strResults & "Pay Rate: " & sngPayRate & vbCrLf
strResults = strResults & "Gross Pay: " & sngGrossPay & vbCrLf
strResults = strResults & "Taxes: " & sngTaxes & vbCrLf
strResults = strResults & "Net Pay: " & sngNetPay
intMsgRes = MsgBox(strResults, vbOKOnly, "Salary")
- Test with these numbers. If you enter hours & rate, your resulting gross, taxes, & net should be the same as mine:
| hours |
rate |
gross |
taxes |
net |
| 30 |
10 |
300 |
60 |
240 |
| 40 |
10 |
400 |
80 |
320 |
| 50 |
10 |
500 |
100 |
400 |
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- What can you think of to do to make this program better?
- Create a new VB program to determine a letter grade given a numberical grade. Consider:
- Read a number grade & display the appropriate letter grade:
| Number Grade |
Letter Grade |
| 93-100 |
A |
| 85-92 |
B |
| 75-84 |
C |
| 65-74 |
D |
| 0-64 |
F |
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "frmGrades.frm" & "vbGrades.vbp"
- What variables do you need?
- Is the number grade variable integer or single?
- What data type is the letter grade variable?
- How will you receive your input (number grade)?
- How will you code the decision the computer needs to make?
- Is the order in which you test number grade important?
- How will you display the result to the user?
- Test all possibilities: 100, 95, 85, 75, 65, 55, 0
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- What can you think of to do to make this program better?
|
| 11 |
09/19/07 |
|
Wednesday - Pledge & Announcements, "vbTicTacToe" |
|
- Classroom Discussion -
- One AM student needed as volunteer to assist with the morning pledge & announcements
- Parental/Guardian signed forms due: no computer contract = no computer use
- Review Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 7 - Making Decisions
- Visual Basic Techniques:
- Line Object - demo on board, properties
- Keeping track of the next player - demo on board
- Change a command button caption by clicking on the button
- Prevent a second click on a button that's already been clicked once
- Check for a winner
- After finding a winner, prevent any more clicks
- Use a Reset command button to restart the game
- Lab Assignment -
- Job Seeking Skills Pre-Test. Click the link & follow the instructions. You get one shot at this one, but it doesn't count. You'll take it again in June to see how much you've learned about job seeking
- Create a Visual Basic game of Tic Tac Toe:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "frmTicTacToe.frm" & "vbTicTacToe.vbp"
- Design the form:
- Exit button, write & test the code
- Nine command buttons arranged 3 by 3 for the game board named:
| cmdTopLeft |
cmdTopCenter |
cmdTopRight |
| cmdMidLeft |
cmdMidCenter |
cmdMidRight |
| cmdBotLeft |
cmdBotCenter |
cmdBotRight |
- Place line objects between the buttons for visual effect
- A label with general instructions
- Another label to display which player plays next
- Remember to use
Option Explicit as the first line in your code window
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Declare Variables:
Dim intMesRet As Integer ' which button the user clicked on in a message window
Dim strNextPlay As String ' either "X" or "O" to indicate which player plays next
Dim blnWinner As Boolean ' prevent further play if you have a winner
- Code for Form_Load()
- Code for cmdTopLeft:
- Code for cmdTopCenter:
- Copy the code from cmdTopLeft to cmdTopCenter
- Change all references from topleft to topcenter
- Test it
- Repeat copy & change for each of the other seven buttons, testing each time
- Consider how to check for a winner -- how many ways can you score three in a row?
- Top row horizontal
- Middle row horizontal
- Bottom row horizontal
- Left column vertical
- Center column vertical
- Right column vertical
- Top left to bottom right diagonal
- Top right to bottom left diagonal
- Code the top-row-horizontal check-for-winner & announce a winner & test it
- Copy & paste the top-row-horizontal check-for-winner & change for middle-row-horizontal
- Copy & paste & change for the other row & column & diagonal
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Keep track of & display how many wins for "X" & how many wins for "O"
- Create a [Reset] command button & write the code
- Tell the user if there is a tie (all buttons filled but no winners)
|
| 12 |
09/20/07 |
|
Thursday - Pledge & Announcements, Microsoft PowerPoint, Math |
|
- Classroom Discussion -
- One AM student needed as volunteer to assist with the morning pledge & announcements
- Parental/Guardian signed forms due: no computer contract = no computer use
- Parts of a computer according to build-your-own-computers.com
- Computer Case
- Motherboard
- CPU
- Memory (RAM)
- Monitor
- Hard drives & Floppy Drives
- CD & DVD Drives
- Video Card
- Keyboard & Mouse
- Sound
- NIC
- Microsoft PowerPoint Online Tutorial from Microsoft
- Math with Ms. Verde
- Lab Assignment -
- Microsoft PowerPoint pratice
- Create a Microsoft PowerPoint presentation on "How to Build Your Own Computer"
- Open Microsoft PowerPoint
- Create a new blank presentation
- Choose a new design (click the menu bar button or F[o]rmat, Slide [D]esign
- Save the presentation to the "My Documents" folder
- Use the filename "css##-Build Your Own Computer.ppt" (use your own css number)
- Title the presentation "How to Build Your Own Computer"
- Add your name & Computer Science as the sub-title on the first page
- Insert a new page
- Title the new page "The Computer Case"
- Add some simple text describing the computer case - perform a Google search if you don't know how a part works
- Locate & copy an image of the computer case (you don't need to save to "My Documents")
- Paste the copied image to the new page
- Repeat for each of the computer parts listed above
- Insert a "Conclusions" or "Summary" or "Questions" or "Sources" page at the end
- Save frequently
- Run the slideshow to see how your presentation looks
- I will copy these presentations to your "H:" drive when we get back to our regular classroom
|
| 13 |
09/21/07 |
|
Friday - Pledge & Announcements, Grade Print Sheet, Finish Tic Tac Toe, VB IF THEN ELSE Statement, "vbSalary2", VB Nested IF THEN ELSE Statement, "vbGrades2" |
|
- Classroom Discussion -
- One AM student needed as volunteer to assist with the morning pledge & announcements
- Parental/Guardian signed forms due: no computer contract = no computer use
- Review Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 7 - Making Decisions
- Review Arithmetic Operators, String Aritmetic Operator, Comparison Operators, Comparison Rules
- The VB IF THEN ELSE Statement:
- Review Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 7 - Making Decisions
- Nested VB IF THEN ELSE Statements:
- Lab Assignment -
- Modify your vbSalary program to work with overtime. Program Logic:
- Hours worked up to & including 40 is normal time & receives normal pay
- Any hours worked over 40 is considered overtime & receives 1.5 times pay rate
- Only hours worked over 40 gets time & a half & this is added to normal 40 hour pay
- The computer must make a decision - use an IF THEN ELSE statement
Some ideas:
- Modify the command button where the work is done:
If sngHoursWorked <= 40 Then
sngGrossPay = sngHoursWorked * sngPayRate
Else
sngGrossPay = (40 * sngPayRate) + ((sngHoursWorked - 40) * sngPayRate * 1.5)
End If
- Test all possibilities: 30 hours, 40 hours, 50 hours
- Test with these numbers. If you enter hours & rate, your resulting gross, taxes, & net should be the same as mine:
| hours |
rate |
gross |
taxes |
net |
| 30 |
10 |
300 |
60 |
240 |
| 40 |
10 |
400 |
80 |
320 |
| 50 |
10 |
550 |
110 |
440 |
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Hours over 60 get double time
- Modify your vbGrades program to use nested IF THEN ELSE statements. Program Logic:
- Perform nested testing to determine where the number grade is
Some ideas:
- Modify the command button where the work is done:
intNumGrade = txtInput.Text
If intNumGrade >= 93 Then
strLetGrade = "A"
ElseIf intNumGrade >= 85 Then
strLetGrade = "B"
ElseIf intNumGrade >= 75 Then
strLetGrade = "C"
ElseIf intNumGrade >= 65 Then
strLetGrade = "D"
Else
strLetGrade = "F"
End If
lblOutput.Caption = strLetGrade
- Add a comment as to how well the student is doing (A=Fantastic, B=Good Job, etc.)
|
|
| 14 |
09/24/07 |
|
Monday - Technology Boolean Logic, VB SELECT CASE Statement, "vbGrades" |
|
- Classroom Discussion -
- Definitions, from Dictionary.com:
- Algebra - A branch of mathematics in which symbols, usually letters of the alphabet, represent numbers or members of a specified set & are used to represent quantities & to express general relationships that hold for all members of the set
- Origins of the word Algebra:
- George Boole (1815-1864) - British mathematician & logician who developed a calculus of symbolic logic:
- Boolean - Of or relating to a logical combinatorial system treating variables, such as propositions & computer logic elements, through the operators AND, OR, NOT, & XOR:
- Boolean Algebra - An algebra in which elements have one of two values & the algebraic operations defined on the set are logical OR, a type of addition, & logical AND, a type of multiplication:
- John Venn (1834-1923) - English logician who introduced Venn diagrams:
- Venn Diagram - A diagram using circles to represent sets, with the position & overlap of the circles indicating the relationships between the sets
- Links:
- Glencoe Boolean Door Locks - Great example of how Boolean works
- IguanaLabs Boolean Truth Tables
- The VB SELECT CASE Statement:
- Simpler way to write a multi-decision, multi-choice process
- Syntax - one value each:
Select Case Expression1
Case value1
One or more Visual Basic statements A
Case value2
One or more Visual Basic statements B
[Case value3
One or more Visual Basic statements C]
[Case Else
One or more Visual Basic statements D]
End Select
- Expression1 is a variable
- IF expression1 is equal to value1 THEN statements A are performed
- IF expression1 is equal to value2 THEN statements B are performed
- IF expression1 is equal to value3 THEN statements C are performed
- IF expression1 is equal to none of the values THEN statements D are performed
- Alternate Syntax - uses < & > symbols:
Select Case Expression2
Case Is Relation1:
One or more Visual Basic statements A
Case Is Relation2:
One or more Visual Basic statements B
[Case Is Relation3:
One or more Visual Basic statements C]
[Case Else:
One or more Visual Basic statements D]
End Select
- IF expression2 is greater or less than (depending on the symbol used) relation1 THEN statements A are performed
- IF expression2 is greater or less than (depending on the symbol used) relation2 THEN statements B are performed
- IF expression2 is greater or less than (depending on the symbol used) relation3 THEN statements C are performed
- IF expression2 is greater or less than (depending on the symbol used) none of the relations THEN statements D are performed
- Alternate Syntax - give a range start to end:
Select Case Expression3
Case value1 To value2:
One or more Visual Basic statements A
Case value3 To value4:
One or more Visual Basic statements B
[Case value5 To value6:
One or more Visual Basic statements C]
[Case Else:
One or more Visual Basic statements D]
End Select
- IF expression3 is between start value1 & end value2 THEN statements A are performed
- IF expression3 is between start value3 & end value4 THEN statements B are performed
- IF expression3 is between start value5 & end value6 THEN statements C are performed
- IF expression3 is between none of the values THEN statements D are performed
- SELECT CASE, used correctly, is a very powerful & easy-to-use programming technique
- SELECT CASE can be much easier to write & understand than complex nested IF THEN ELSE statements
- Lab Assignment -
- Create the "vbGrades" program as defined on Tuesday & Friday last week
|
| 15 |
09/25/07 |
|
Tuesday - Math Time-Value-of-Money, VB Built-in-Formulas, "vbMoney" part I |
|
- Classroom Discussion -
- Time Value of Money - Is it better to have money now rather than later?
- Time Value of Money - VB Formulas:
- Visual Basic Pre-Defined Built-In Functions:
- IsNumeric("string") ' returns True if string is only numbers
- Visual Basic Pre-Defined Built-In Functions:
- Lab Assignment -
- Create a VB program to view time-value of money Future-Value calculations:
I want to put aside money now & see how it'll grow over time
- Future Value of Savings
- You need to know four things:
- Value - How much you're starting with
- Deposit - How much you'll deposit every month
- Interest Rate - How much the bank pays you to save your money with them
- Length of Term - How long you're planning to save
For your calculations:
- Use the VB IDE to help you place the variables in the function
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "frmMoney.frm" & "vbMoney.vbp"
- Add textboxes for input:
- txtValue
- txtDeposit
- txtRate
- txtTerm
- Add a label for output:
- lblOutput
- Add labels to identify all textboxes
- Add instructions to the user
- Add variables at the top of the program:
- dblValue
- dblDeposit
- dblRate
- dblTerm
- dblFuture
- intMesRet
- Add command buttons:
- Future Value
- Exit
- Steps for the Calculate Future Value button:
- Test each input textbox for numeric & then convert to data type double (use "CDbl(txtInput.text)") of the textbox to the variable
- Assign the result of the predefined Visual Basic function "FV" to the output variable
- Display the variable, formatted as currency, on the output label
- Add a command button & code & "cancel" for exit
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance). Use numbers that are easy to confirm. For example:
| Starting Value Only, No Deposits |
| Value |
Deposit |
Rate |
Term |
Total Deposits |
Value |
| 100 |
0 |
5 |
1 |
$100 |
$105.12 |
| 100 |
0 |
10 |
1 |
$100 |
$110.47 |
| 100 |
0 |
10 |
10 |
$100 |
$270.70 |
| 1000 |
0 |
10 |
40 |
$1000 |
$53,70.67 |
| Starting Value With Deposits |
| Value |
Deposit |
Rate |
Term |
Total Deposits |
Value |
| 100 |
10 |
5 |
1 |
$220 |
$227.90 |
| 100 |
10 |
10 |
1 |
$220 |
$236.13 |
| 100 |
10 |
10 |
10 |
$1,300 |
$2,319.15 |
| 1000 |
100 |
10 |
40 |
$49,000 |
$686,10.86 |
- Calculate & display the extra money gained through interest over time
|
| 16 |
09/26/07 |
|
Wednesday - Career Job-Seeking-Skills pre-test, "vbMoney" part II |
|
- Classroom Discussion -
- Flyers on Board
- Ocean County College registrations form due Monday, October 1st
- Career - Job Hunting
- Time-Value of Money - the Rule of 72
- Visual Basic Pre-Defined Built-In Functions:
- IsNumeric("string") ' returns True if string is only numbers
- Visual Basic Pre-Defined Built-In Functions:
- Lab Assignment -
- Modify the time-value of money VB program to view Payment calculations:
I want to see how much I have to pay each month to pay off a loan
- How much will you need to save each month to reach a certain value
- You need to know three things:
- Value - How much you have to pay off at the end of the term
- Interest Rate - How much the bank is charging you for you to borrow their money
- Length of Term - How long you have to pay
For your calculations:
- Use the VB IDE to help you place the variables in the function
Some ideas:
- Modify your existing "money.vbp" to add a new process
- Add a new command button:
- Calculate Payment
- Steps for the Calculate Future Value button:
- Test each input textbox for numeric & then convert to data type double (use "CDbl(txtInput.text)") of the textbox to the variable
- Assign the result of the predefined Visual Basic function "PMT" to the output variable
- Display the variable, formatted as currency, on the output label
- Add a command button & code & "cancel" for exit
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Test & debug your program (call me for assistance). Use numbers that are easy to confirm. For example:
| Final |
Rate |
Term |
Value |
| 1000 |
3 |
3 |
$26.58 |
| 10000 |
3 |
5 |
$154.69 |
| 20900 |
2.99 |
5 |
$323.38 |
| 25000 |
3 |
5 |
$386.75 |
- Calculate & display the true cost of the loan
|
| 17 |
09/27/07 |
|
Thursday - English 2nd-Year Students visit with Ms. Gerick, "vbDates" |
|
- Classroom Discussion -
- Ocean County College registrations form due Monday, October 1st
- English: Second-year students will visit with Ms. Gerick to work on a portfolio
- Vocabulary:
- Data Validation: the process of ensuring that a program operates on clean, correct and useful data (wikipedia.org)
- Visual Basic Pre-Defined Built-In Functions:
- Date ' returns today's date as data type date
- IsDate("string date") ' returns True if the string date is a valid date
- CVDate("string date") ' returns the string date as data type date
- Visual Basic Pre-Defined Built-In Functions:
- Lab Assignment -
- Create a Visual Basic program called "dates" to calculate how many days are between two user-entered dates
- How will you allow the user to enter two dates?
- What data type will you use to store the two user-entered dates?
- What data type will you use to store the difference between the two dates?
- How will you display the answer to the user?
For your calculations:
- Supply today's date for the user to either accept or change
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "dates.frm" & "dates.vbp"
- Add 2 textbox for input & a label for output:
- txtDate1
- txtDate2
- lblOutput
- Add labels to identify the textbox
- Add variables at the top of the program:
- intMesRet
- dte1
- dte2
- intDaysBetween
- Add command buttons:
- cmdGo
- cmdExit
- Program & test the Exit command button
- Steps for the Go command button:
- Use "IsDate()" to ensure that the user entered a valid txtDate1.text
- Else display an appropriate error message & set the focus to txtDate1
- Use "IsDate()" to ensure that the user entered a valid txtDate2.text
- Else display an appropriate error message & set the focus to txtDate2
- Continue only if both textbox are valid dates
- Convert txtDate1.text to data type date & store in variable dte1
- Convert txtDate2.text to data type date & store in variable dte2
- Calculate the difference between the two date variables & store in variable intDaysBetween
- Display variable intDaysBetween to the user on lblOutput.caption with an appropriate message
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Always display a positive number of days between, never a negative, for example: 9/05-9/25 = -18
|
| 18 |
09/28/07 |
|
Friday - SkillsUSA, Visual Basic Quiz 3, "vbMadLibs" |
|
- Classroom Discussion -
- Ocean County College registrations form due Monday, October 1st
- Skills USA
- Technology Vocabulary:
- Concatenate - To arrange (strings of characters) into a chained list
- Mad Libs - wikipedia.org - definition
- penguinGroup.com - Mad Libs online game & instructions
- The concatenate symbol is " & "
- Examples:
dim strWord1 as String
dim strWord2 as String
dim strOutput as String
strword1 = "large"
strword2 = "house"
strOutput = "Hello " & "World!"
strOutput = "Hello " & strWord1 & " World!"
strOutput = "Hello " & strWord1 & " " & strWord2 & " World!"
strOutput = "Hello " & txtFirstName.Text & " " & txtLastName.Text & _
", Welcome to my " & strWord1 & " " & strWord2
VB Syntax to add to an existing string variable:
strOutput = "First line of text" & VbCrLf
strOutput = strOutput & "Second line of text" & VbCrLf
strOutput = strOutput & "Third line of text" & VbCrLf
strOutput = strOutput & "Fourth line of text" & VbCrLf
Here's how the above code will display:
First line of text
Second line of text
Third line of text
Fourth line of text
- Lab Assignment -
- Create a Visual Basic program called "madLibs" to play the famous game on computer
Use between five (5) & ten (10) user-supplied words:
- What story will you chose? Will you make one up? Will you borrow one from the internet?
- What words will you replace in the story with user-supplied words?
- How will the user enter the words to be replaced?
- What variables will you need? What data types?
- How will you display the changed story to the user?
Some ideas:
- Open VB & create a new, standard.exe
- Save the form & project to your "My Documents/vb" folder as "madLibs.frm" & "madLibs.vbp"
- Add up to 10 textbox for input
- Use a textbox for output so the user may highlight & copy the madlibs story
- Name each input textbox & output textbox appropriately
- Set the output textbox properties "MultiLine = True" & "ScrollBars = 2 - Vertical"
- Add labels to identify what the user needs to type into each textbox
- Add any variables at the top of the program & be sure to use Option Explicit
- Add & program & test the EXIT command button
- Add & program a GO command button:
- Sequentially test each input textbox for not blank
- It any input textbox is blank, use a msgbox to tell the user & set the focus to that input textbox
- Use concatenation to build the story output variable
- Mix the words the user has entered into the textboxes with the existing story
- Display the story output variable onto the output textbox
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Let the user choose from more than one story & use the same user-supplied words
|
|
| 19 |
10/01/07 |
|
Monday - VB Loops, "vbNumberLoops" |
|
- Classroom Discussion -
- Definitions:
- Loop - A sequence of instructions that repeats either a specified number of times or until a particular condition is met
- Iterate - To say or perform again
- Iteration - The process of repeating a set of instructions a specified number of times or until a specific result is achieved
- Infinite Loop - One that never terminates
- Sentinel - One that keeps guard
- Sentinel Variable - A variable that changes to determine when a program loop stops looping
- Usage:
- Works with comparison tests, just like decisions
- The six comparision operators ( < > = <= >= <> ) work just the same
- The block of code continues being interpreted & executed as long as the comparison returns a TRUE result
- When the comparison returns a FALSE result, the loop ends & the program continues with the first statement after the LOOP statement
- It's possible to have a loop where the comparison test returns a FALSE the first time it's tested - the block of statements will never be executed
- It's also possible to have a loop where the comparison test never changes to return a FALSE & therefor never exits
- A never-ending-loop is one where the sentinel variable never changes so that the comparison never returns a FALSE condition & the loop never ends
- Rules: STP
- Sentinel Variable - The variable that will be tested as part of the comparison
- Start - Initialize the sentinel variable to some value before the start of the loop
- Test - The comparison test will determine if the block of statements in the loop execute
- Change - Modify the value of the sentinel variable inside the loop block
- Warnings:
SAVE YOUR PROGRAM BEFORE TESTING A LOOP
- You'll get an infinite loop if the sentinel variable does not change to make the comparison FALSE
- If an infinite loop condition occurs, you may have to reset your computer & will lose any changes that have not been saved
- If you get an infinite loop, wait, Windows may detect it & display a message box saying you have a slow running program & asking if you want to abort it - answer yes
- Loop Safety:
- You set it up during testing
- Create a variable Dim intSafety As Integer
- Before you start the loop, initialize intSafety = 0
- Inside the loop, decrement intSafety = intSafety + 1
- Inside the loop, test If intSafety > 10000 Then display an exit message & End Sub
- VB Picture Box object - can display (print) multiple lines:
picOutput.Print ("hello world") ' print string literal
strOutput = "My name is Mike" ' initialize a variable
picOutput.Print (strOutput) ' print a variable
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Loop Syntax:
- Syntax of the DO WHILE LOOP:
Do While comparisontest1
Block of one or more Visual Basic statements A
Change the sentinel variable
Loop
DO WHILE will execute statements A while comparisontest 1 is TRUE
If FALSE the first time, statements A will never be executed
- Syntax of the DO UNTIL LOOP:
Do Until comparisontest2
Block of one or more Visual Basic statements B
Change the sentinel variable
Loop
DO UNTIL will execute statements B until comparisontest 2 becomes TRUE
If TRUE the first time, statements B will never be executed
- Syntax of the DO LOOP WHILE:
Do
Block of one or more Visual Basic statements C
Change the sentinel variable
Loop While comparisontest3
Similar to the DO UNTIL execute statements C while comparison test 3 is TRUE
Will ALWAYS execute statements C at least once
- Syntax of the DO LOOP UNTIL:
Do
Block of one or more Visual Basic statements D
Change the sentinel variable
Loop Until comparisontest4
Similar to the DO UNTIL execute statements D until comparison test 4 becomes TRUE
Will ALWAYS execute statements D at least once
- Syntax of the FOR NEXT:
For counterVar = startVal To endVal [Step incrementVal]
Block of one or more Visual Basic statements E
The sentinel variable (counterVar) changes automatically
Next CounterVar
Will execute statements E (endVal - startVal) times
If startVal is greater than endVal, will not execute statements E at all
- Lab Assignment -
- On-screen practice with Picture Box object & print:
- Add a picture box object titled "picOutput", make it large
- Display "Hello World" to the picture box object inside a command button event
- Initialize a string variable & display the contents
- Use "picOutput.Cls" inside another command button event to clear screen the picture box
- Create a Visual Basic program "vbNumberLoops" to display number sequences:
- Display a series of numbers from 1 to 10
- Display odd numbers from 1 to 10
- Display multiples of three (3,6,9,etc.)
- Use a textbox to get a start number where the user wants the loop to begin
- Use a textbox to get a stop number where the user wants the loop to end
- Use a textbox to get a step number how the user wants to skip (ie: 2 4 6 or 3 6 9 etc.)
- Modify your "vbNumberLoops" program to display the sum of all numbers between user supplied start & stop numbers
|
| 20 |
10/02/07 |
|
Tuesday - VB Loop Practice, "vbPrime", "vbFactorial" |
|
- Classroom Discussion -
- Respect - wikipedia.org
- Respect - dictionary.com
- Respect - goodCharacter.com
- Responsibility - goodCharacter.com
- Responsibility - dictionary.com
- Review VB Loops
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Definitions:
- Sum - an amount obtained as a result of adding numbers
for example: the first five integers from 1 to 5 = 1 + 2 + 3 + 4 + 5 = 15
- Factorial - the product of all the positive integers from 1 to a given number
for example: the first five integers from 1 to 5 = 1 * 2 * 3 * 4 * 5 = 120
- Prime - a positive integer not evenly divisible by any positive integer other than itself & one
for example: 2 is Prime, 3 is Prime, 5 is Prime
besides 2, no even number is Prime
- Visual Basic MOD - divide two numbers & return only the remainder as an integer
intRemainder = 5 mod 3 ' returns 2
Useful to see if a number can be divided evenly by another number
intRemainder = 5 mod 2 ' returns 1 - means that 5 is an odd number
intRemainder = 6 mod 2 ' returns 0 - means that 6 is an even number
Here is an example:
intSentinel = 1
Do While intSentinel < 25
If intSentinel Mod 2 = 0 Then
picOutput.Print (intSentinel & " is an even number")
End If
intSentinel = intSentinel + 1
Loop
- Lab Assignment -
- Pen & Paper Assignment:
- Write your name & today's date on top of the paper
- Hand in when complete
- Hand-write the syntax of the five (5) different VB loops
- After each loop syntax, write an example of a program segment that will display numbers from 1 to 10
- For example (here's the first loop)
1st LOOP SYNTAX:
Do While comparison
Perform these statements
Change the sentinel variable
Loop
1st LOOP EXAMPLE:
intCount = 1
Do While intCount <= 10
txtOutput.Text = txtOutput.Text & intCount & VbCrLf
intCount = intCount + 1
Loop
- Create a Visual Basic program "vbSumsOfConsecutiveNumbers" to display sums of consecutive numbers starting with a user supplied number & a user supplied "how many"
- Create a Visual Basic program "vbFactorial" to display Factorial for a user supplied number
- Create a Visual Basic program "vbPrime" to display if a user supplied number is Prime or not
- Modify "vbPrime" to display all the Prime numbers between 2 & a user supplied number
|
| 21 |
10/03/07 |
|
Wednesday - Career, VB Loop Practice, "vbStars" |
|
- Classroom Discussion -
- Career - 7 Steps to Get a Job:
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Review VB Loops
- Syntax of the FOR NEXT:
For counterVar = startVal To endVal [Step incrementVal]
Block of one or more Visual Basic statements E
The sentinel variable (counterVar) changes automatically
Next CounterVar
Will execute statements E (endVal - startVal) times
If startVal is greater than endVal, will not execute statements E at all
- Lab Assignment -
- Create a new Visual Basic program to use loops to draw shapes with one character:
- Open Visual Basic & create a new standard executable
- Name the form "frmStars.frm" & the project "vbStars.vbp"
- Add a large picture box object for output
- Add a textbox object & label for to let the user specify how many
- Add a textbox object & label for to let the user specify the symbol
- Add a command button object & code to draw one symbol
- Add a command button object & code to draw a row of symbols
- Add a command button object & code to draw a box of symbols
- Add a command button object & code to draw a right triangle of symbols
- Add a command button object & code to draw a left-sided right triangle of symbols
- Add a command button object & code to draw an isosceles triangle of symbols
- Add a command button object & code to draw a diamond (2 isosceles triangles touching at the bottoms, the lower triangle upside-down)
- Add a command button object & code to draw an hourglass (2 isosceles triangles touching at the tips, the upper triangle upside-down)
|
| 22 |
10/04/07 |
|
Thursday - English, VB Loop Review, Quiz VB Decisions & Loops, "vbGCD" |
|
- Classroom Discussion -
- Reminder - No School on:
- Friday - October 5th - Teacher In-Service
- Monday - October 8th - Columbus Day
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Review VB Loops
- Lab Assignment -
- Visual Basic Quiz 2. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Quiz Part II - Design, write, create, test, run, & save a Visual Basic program to determine the Greatest Common Denominator between two input numbers. GCD is found by determining the highest number that divides evenly into both of the two input numbers. For instance:
given num1 = 12 & num2 = 18 then gcd = 6
given num1 = 12 & num2 = 21 then gcd = 3
given num1 = 12 & num2 = 24 then gcd = 12
given num1 = 12 & num2 = 28 then gcd = 4
given num1 = 28 & num2 = 12 then gcd = 4
- Run a loop
- Stop when you reach the smaller number
- Keep track of whenever you find a number that divides evenly into both input numbers
- Call your form "frmGCD.frm" & your project "vbGCD.vbp"
- Think before you start
- What form objects will you use?
- What variables will you use?
- What processes will you use?
- How do you determine a denominator?
- How do you determine the greatest common
denominator?
- Test frequently
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- When complete, copy to your "Z:/toBeGraded" folder so I can grade it
- Grading Criteria:
- Form must be named
- Form objects (except labels) must be named
- You must have your name, date, & program name as comments at the top of the code
- You must use "Option Explicit"
- Variables must be named & declared
- Exit button must ask if I really want to exit
- Determine button must provide the correct answer to all test input. I will test with the numbers given above
- Output must echo user input so that the user can see & fix his own misteaks
- Output must show the correct answer
- Use enough text in the output to describe what the numbers mean
- Open online book, open notes, you may ask clarification questions but I will not code this for you, you may NOT ask your fellow students for help
- Take as much time as you need to get it right
- If we have time, we'll complete the vbStars loop practice program from yesterday on the board together
- HAVE A GRAND WEEKEND!!!
|
|
10/05/07 |
|
Friday - OCVTS School Closed - Teacher In-Service |
|
|
10/08/07 |
|
Monday - OCVTS School Closed - Columbus Day |
| 23 |
10/09/07 |
|
Tuesday - VB Loop Practice, "vbFactorial" |
|
- Classroom Discussion -
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Vocabulary Definitions:
- Factorial - the product of all the positive integers from 1 to a given number
for example: Factorial the first five integers from 1 to 5 = 1 * 2 * 3 * 4 * 5 = 120
- Flowchart - a schematic representation of a sequence of operations, as in a manufacturing process or computer program
- wikipedia.org
- Pseudocode - a notation resembling a programming language but not intended for actual compilation. It usually combines some of the structure of a programming language with an informal natural-language description of the computations to be carried out
-
- Boolean Logic in Programming
| NOT |
TRUE |
FALSE |
|
FALSE |
TRUE |
|
(make opposite) |
|
|
| OR |
TRUE |
FALSE |
| TRUE |
TRUE |
TRUE |
| FALSE |
TRUE |
FALSE |
| (ONE must be TRUE) |
|
|
| AND |
TRUE |
FALSE |
| TRUE |
TRUE |
FALSE |
| FALSE |
FALSE |
FALSE |
| (BOTH must be TRUE) |
|
- Boolean Logic in Programming & PEMDAS
- Parenthesis
- AND is like Multiply
- OR is like Add
- The AND pair will compare before the OR pair
- To make the OR pair compare before the & pair, you MUST USE PARENTHESIS!!!
- Boolean Logic in Programming Examples. Use NOT to reverse the logic:
- NOT TRUE
- NOT FALSE
- NOT intMesRet = vbNo
- NOT strQuitGame = vbYes
Use OR to compare two possible answers to the same variable:
- strDirection = "up" OR strDirection = "down"
- strAnswer = "YES" OR strAnswer = "yes"
- intAge = 17 OR intAge <> 17
- strHaveCar = "Y" OR strHaveCar = "y"
- dtmDay = "Saturday" OR dtmDay = "Sunday" OR blnHoliday = TRUE
- isNumeric(txtNum1.text) OR isNumeric(txtNum2.text)
- strHaveCar = "Y" OR strHaveRide = "Y" OR strBusRide = "Y"
- strTrafficLight = "Yellow" OR strTrafficLight = "Red" OR strTrafficSign = "Stop"
- strTrafficLight = "Red" OR blnCarInFrontOfYou = TRUE
Use & to compare two possible answers to different variables:
- strDirection = "up" AND strAnswer = "yes"
- intAge >= 17 AND strHaveCar = "Y"
- dtmDay = "Monday" AND blnHoliday = TRUE
- isNumeric(txtNum1.text) AND isNumeric(txtNum2.text)
- strTrafficLight = "Yellow" AND blnJustTurnedYellow = FALSE
- strTrafficLight = "Yellow" AND intTurnedYellowSeconds > 5
- strTrafficLight = "Green" AND blnCarInFrontOfYou = FALSE
- cmdTopLeft <> "" AND cmdTopLeft = cmdTopCenter AND cmdTopCenter = cmdTopRight
Use complex logic & PEMDAS to compare different combinations of answers:
- strHaveCar = "Y" AND strHaveLicense = "Y" OR strBusRide = "Y"
- blnSchoolOpen = TRUE AND strHaveRide = "Y" OR strBusRide = "Y"
- blnSchoolOpen = TRUE AND (strHaveRide = "Y" OR strBusRide = "Y")
- Lab Assignment -
- Create a Visual Basic program "vbFactorial" to show the factorial of a user-entered number:
- Product means multiply
- Design the form:
- Define your variables:
Option Explicit
Dim intMesRet As Integer ' for messages
Dim intNum As Integer ' to hold the number the user wants to factorialize
Dim lngFact As Long ' to hold the factorial product value
Dim intCount As Integer ' the sentinel variable
- Write the code for the cmdExit button
- Write the code for the cmdFact button: (This is called "pseudo-code")
If the value in the input textbox is not numeric
Tell the user & place the focus
Else
If the value in the textbox is larger than 12
Tell the user that bigger than 12 is no good & use 5
end if
Assign the value of 1 to lngFact
Assign the value from the input textbox to intNum
Initialize the sentinel variable to 1
Loop while the sentinel is less than or equal to intNum
Assign the result of lngFact times intCount to lngFact
Increment the sentinel
End loop
Display the output to the user
End If
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
|
| 24 |
10/10/07 |
|
Wednesday - College-Bound Planning, "vbPrime" |
|
- Classroom Discussion -
- Career - College-Bound High School Senior Planning Calendar
- Prime - a positive integer not evenly divisible by any positive integer other than itself & one
for example: 2 is Prime, 3 is Prime, 5 is Prime
besides 2, no even number is Prime
- Modulus - an operation that finds the remainder of division of one number by another as a whole integer number
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Review of Boolean Logic in Programming
- Lab Assignment -
- Create a new Visual Basic program "vbPrime" to say if a user-entered number is Prime or not:
|
| 25 |
10/11/07 |
|
Thursday - Guest Speaker from NJIT, modify "vbPrime" |
|
- Classroom Discussion -
- Guest speaker from NJIT (10:00 am & 11:00 am)
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Review of Boolean Logic in Programming
- Lab Assignment -
- Modify the VB program "vbPrime" from yesterday:
- Add a command button "cmdShowPrimes"
- Program the button to display all Prime numbers between 2 & a user-selected number
- Create variables (if you haven't already):
userNumber
intSentinel_1
intSentinel_2
isPrime
strOut
- Pseudocode:
if the input textbox is not numeric
tell the user
set the focus
else
save the textbox as a userNumber variable
initialize intSentinel_1 to 2 ' 0 & 1 are not Prime
loop_1 from 2 through userNumber ' run them all
'determine if intSentinel for loop_1 is Prime
initialize intSentinel_2 to 2 ' start at 2
initialize isPrime to True ' assume intSentinel_1 is Prime
initialize strOut to Null ' ("")
loop_2 from 2 through half of intSentinel_1 ' run through half
' half of 23 (1 - 12) because 13 - 22 will NEVER divide evenly into 23
if (intSentinel_1 mod intSentinel_2) = 0 ' no remainder
set isPrime to False ' because no remainder, intSentinel_1 is NOT Prime
set intSentinel_2 equal to intSentinel_1 ' end loop_2 early
end if
end loop_2
if isPrime = True
display intSentinel_1
end if
end loop_1
end if
- Text with numbers you know: Prime numbers between 2 & 23 are: 2, 3, 5, 7, 11, 13, 17, 19, 23
- 23 is Prime, so if you display all Primes between 2 & 23, 23 should be displayed as prime
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Get rid of the last comma
|
| 26 |
10/12/07 |
|
Friday - Quiz Boolean Logic, "vbTimesTable", "vbTimesTableGame" |
|
- Classroom Discussion -
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 8 - Visual Basic Looping
- Review of Boolean Logic in Programming
- Vocabulary:
- Random - unpredictable
- Random Number - a number chosen by a random sampling, as from a table (random number table) or generated by a computer
- VB6 Rnd() Function - returns a pseudo-random number between 0.0 & 0.9999999
- To get a number between intHigh & intLow use where intHigh is the highest & intLow is the lowest possible number you want:
intRandomNumber = ((intHigh - intLow + 1) * Rnd) + intLow
- For example, to simulate a roll of 2 dice (return 2 numbers between 1 & 6) use:
intHigh = 6
intLow = 1
intDie1 = ((intHigh - intLow + 1) * Rnd) + intLow
intDie2 = ((intHigh - intLow + 1) * Rnd) + intLow
intDiceTotal = intDie1 + intDie2
- vbExplorer.com - Random Numbers Tutorial
- Lab Assignment -
- Boolean Logic Quiz. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Create a new VB program "vbTimesTable":
- Create a new VB executable
- Add 2 command button objects & 1 textbox object
- Name the objects
- Write the code for the Exit button
- Write the code for the Go button to display a times table in the picture box
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Right align the numbers in the columns:
| Left | Right |
| (Wrong) | (Right) |
| 1 | 1 |
| 10 | 10 |
| 100 | 100 |
- Create a new VB program "vbTimesTableGame":
- Create a new VB executable
- Add command button objects & 1 textbox object
- Name the objects
- Write the code for the Exit button
- Write the code for the New Problem button to randomly choose & display two numbers between 1 & 12
- Write the code for the Check Answer button to determine if the user answer is correct
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Create & code a Clear All command button objectto clear all display objects
- Complete any incomplete programs
|
|
| 27 |
10/15/07 |
|
Monday - Sub-Routines, "vbDistanceConverter" |
|
- Classroom Discussion -
- Definitions:
- Procedure - An ordered set of tasks for performing some action
- Routine - A section of a program that performs a particular task
- Subroutine - A set of instructions that performs a specific task for a main routine, requiring direction back to the proper place in the main routine on completion of the task
- Function - A named section of a program that performs a specific task
- The terms routine, procedure, function, & subroutine are synonymous
- Synonymous - Having the same or a similar meaning
- Some programming languages (Visual Basic) make a distinction between a function, which returns a value, & a procedure, which performs some operation but does not return a value
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Examples:
' Subroutine calling statement
Call getNormalPay()
' Subroutine called statement
Private Sub getNormalPay()
sngGrossPay = (sngHoursWorked * sngPayRate)
End Sub
' Function calling statement
sngGrossPay = getNormalPay()
' Function called statement
Private Function getNormalPay() As Single
getNormalPay = (sngHoursWorked * sngPayRate)
End Function
- Lab Assignment -
- Onboard demo & practice with sub-routines
- Write a VB program "vbDistance" to use sub-routines to convert user-supplied distance number from English to metric & back:
- Convert between these distances:
- Inches & Centimeters
- Feet & Meters
- Miles & Kilometers
- Design the form:
- 1 Textbox Object for input
- 6 Command Button Objects for event processes
- 1 Label Object for output
- Name the Objects
- Labels to tell the user what to do
- Create Global variables:
Option Explicit
Dim sngNumIn As Single
Dim strOutput As String
- Pseudocode for the process of one command button, "cmdInchesToCentimeters":
Ensure the input textbox is a number
Assign the input textbox number to a variable distance input
Calculate the converted distance as input times 2.54
Display the converted distance with enough information so that the user knows what happened
- Test
- Code the other buttons, testing as you go
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Are there any other distances you could convert?
|
| 28 |
10/16/07 |
|
Tuesday - Sub-Routines, "vbTicTacToe2" |
|
- Classroom Discussion -
- Definitions:
- Algorithm - A step-by-step problem-solving procedure, especially an established, recursive computational procedure for solving a problem in a finite number of steps
- Flowchart - A schematic representation of an algorithm or a process
- Schematic - A diagram that represents the elements of a system using abstract, graphic symbols rather than realistic pictures
- Process - A naturally occurring or designed sequence of changes of properties or attributes of an object or system
- Pseudocode - A notation resembling a programming language but not intended for actual compilation
- Sites:
- Minich.com - Clean & understandable description of sub-routines & functions
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Lab Assignment -
- Re-write the "vbTicTacToe" program to use sub-routines
- Reduce the program from 200 lines to 143 by using sub-routines
- Copy your original "vbTicTacToe" folder, rename the copy as "vbTicTacToe2"
- Open & modify
- Pseudocode:
Move any duplicative code into sub-routines or functions
Call the new sub-routine or function where the original lines were
- "checkWinner()" is a function, we have nine repetitious sets of four lines like this:
If cmdTopLeft.Caption <> "" And cmdTopLeft.Caption = cmdTopCenter.Caption And cmdTopCenter.Caption = cmdTopRight.Caption Then
blnWinner = True
intMesRet = MsgBox("Winner is " & cmdTopLeft.Caption, vbOKOnly)
End If
- Create a new function "inARow()" to do this stuff, using variables for each button:
Private Function inARow(butt1 As String, butt2 As String, butt3 As String)
If butt1 <> "" And butt1 = butt2 And butt1 = butt3 Then
blnWinner = True
intMesRet = MsgBox("Winner is " & butt1, vbOKOnly)
End If
End Function
- Now, replace each of the nine sets of four lines with this call statement:
intMesRet = inARow(cmdTopLeft.Caption, cmdTopCenter.Caption, cmdTopRight.Caption)
Changing the names of the buttons for each row, column, diagonal as required to test each of the eight possible winning combinations
- Test, Test, Test
- Now look at the code for the "cmdTopLeft_Click()" command button, we have 12 lines that repeat. I can't use variables to change the line that changes the caption on the command button:
cmdTopLeft.Caption = strNextPlay ' change button caption to "X" or "O"
- I won't change the two lines above it
If Not blnWinner Then ' only if no winner yet
If cmdTopLeft.Caption <> "X" And cmdTopLeft.Caption <> "O" Then
- But I can only move the seven lines below it to another function:
If strNextPlay = "X" Then ' change next player
strNextPlay = "O"
Else
strNextPlay = "X"
End If
lblNextPlay.Caption = strNextPlay ' show who plays next
checkWinner ' check for a winner
- Create a new function "changePlay()":
Private Function changePlay()
If strNextPlay = "X" Then
strNextPlay = "O"
Else
strNextPlay = "X"
End If
lblNextPlay.Caption = strNextPlay
checkWinner
End Function
- Then replace all nine occurances of the seven lines for every button with this call statement:
changePlay
- Test, Test, Test
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
|
| 29 |
10/17/07 |
|
Wednesday - Career, Sub-Routines, "vbSalary2" |
|
- Classroom Discussion -
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Lab Assignment -
- Online career assessment from LiveCareer.com:
- Signup
- Take the 100-question assessment
- Choose the best answer out of the three choices
- Read the results
- Print out the chart on page 8
- Put your name on the printed page
- Hand in the chart
Remember - Don't sign up for any advertizements & don't pay for stuff on the internet
- Re-write the "vbSalary" program to use sub-routines:
- Design the form:
- 2 Textbox Objects for input
- 2 Command Button Objects for event processes
- 3 Label Object for output
- Name the Objects
- Labels to tell the user what to do
- Create Global variables:
Option Explicit
Dim sngHoursWorked As Single
Dim sngPayRate As Single
Dim sngGrossPay As Single
Dim sngTaxes As Single
Dim sngNetPay As Single
- Pseudocode for the process of the "cmdGo" command button:
If the Hours Worked textbox is not numeric
Display an error message & set focus
ElseIf the Pay Rate textbox is numeric
Display an error message & set focus
Else
Assign the value in Hours Worked textbox to variable "sngHoursWorked"
Assign the value in Pay Rate textbox to variable "sngPayRate"
If Hours Worked is less than or equal to 40
Calculate Gross Pay as Hours Worked times Pay Rate
Else
Calculate Gross Pay as Hours Worked times Pay Rate plus
(Hours Worked - 40) times Pay Rate times 50%
End If
Calculate Taxes as 20% of Gross Pay
Calculate Net Pay as Gross Pay minus Taxes
Display Gross Pay to the user
Display Taxes to the user
Display Net Pay to the user
End If
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Format your output for currency
|
| 30 |
10/18/07 |
|
Thursday - Math, Sub-Routines, "vbGrades2" |
|
- Classroom Discussion -
- Math - Ms. Verde & Greatest Common Denominator (GCD) & Least Common Denominator (LCD)
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Lab Assignment -
- Re-write the "vbGrades" program to use sub-routines:
- Copy your existing "vbGrades" to "vbGrades2"
- Redesign the form for textbox input named "txtInput" & label output named "lblOutput"
- Variables:
Option Explicit
Dim sngNumberGrade As Single
Dim strLetterGrade As String
Dim intMsgRes As Integer
Dim strResults As String
Dim strMessage As String
- Pseudocode for command button object "Go":
Populate variable sngNumberGrade using a function "getNumberGrade()"
Populate variable strLetterGrade using a function "getLetterGrade()"
Popluate variable strMessage using a function "getMessage()"
Call a subroutine "displayResults()" to display the results
- Pseudocode for function "getNumberGrade()"
If the input textbox is not numeric
Display a message for the user
Set the focus
Set variable "getNumberGrade" to -1 minus one
else
Set variable "getNumberGrade" to the contents of the input textbox
- Pseudocode for function "getLetterGrade()"
Use a case or nested if statement to assign variable "getLetterGrade"
if sngNumberGrade >= 93 then getLetterGrade = "A"
if sngNumberGrade >= 85 then getLetterGrade = "B"
if sngNumberGrade >= 75 then getLetterGrade = "C"
if sngNumberGrade >= 70 then getLetterGrade = "D"
if sngNumberGrade >= 0 then getLetterGrade = "F"
else getLetterGrade = "Oops"
- Pseudocode for function "getMessage()"
Use a case or nested if statement to assign variable "getMessage"
if strLetterGrade = "A" then getMessage = "Great work"
if strLetterGrade = "B" then getMessage = "Almost there"
if strLetterGrade = "C" then getMessage = "Keep on trying"
if strLetterGrade = "D" then getMessage = "Ask for help"
if strLetterGrade = "F" then getMessage = "Maybe try som other career"
else getMessage = "Invalid input"
- Pseudocode for sub-routine "displayResults()"
Populate variable strResults with some appropriate message like:
"A number grade of 95"
"Gets a letter grade of "A"
"Great Work"
Display variable strResults to the output label caption
Set the focus back to the input textbox
- Code for "GotFocus()"
' only works if your textbox is named "txtInput"
Private Sub txtInput_GotFocus()
txtInput.SelStart = 0
txtInput.SelLength = Len(txtInput.Text)
End Sub
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- ???
|
| 31 |
10/19/07 |
|
Friday - SkillsUSA, Sub-Routines, "vbGCF" |
|
- Classroom Discussion -
- SkillsUSA - New Jersey website
- Greatest Common Factor (GCF) - The greatest common factor (GCF) is the greatest factor that divides two numbers
- Least Common Multiple (LCM) - The least common multiple (LCM) of two numbers is the smallest non-zero number that is a multiple of both
- Pass an argument as a parameter into a sub-routine or function:
- Declare the parameters as variables inside the parenthesis
- For example, a subroutine to display information, an integer number "n1" & a text string "s1":
Private Sub CommandShowAge_Click()
Call showage(17, "Your Age")
End Sub
- Call the sub-routine or function with values or variables inside the calling statement parenthesis, for example, 17 & "Your Age":
Private Sub showage(n1 As Integer, s1 As String) As Integer
MsgBox s1 & " is " & n1
End Sub
- Explanation:
- The number 17 is passed into the local variable "n1"
- The text string literal "Your Age" is passed into the local variable "s1"
- The message box displays "Your Age is 17"
- Sub-routines don't return a value to the calling statement
- Test it
- Another example, a function to multiply two numbers:
Private Sub Multiply_Click()
Dim n1 As Integer
Dim n2 As Integer
Dim ans As Integer
n1 = 5
n2 = 7
ans = mult2numbers(n1, n2)
MsgBox n1 & " x " & n2 & " = " & ans
End Sub
- Since a function will return ONE AND ONLY ONE result, call a function by using it on the right side of an equals sign:
Private Function mult2numbers(a As Integer, b As Integer) As Integer
mult2numbers = a * b
End Function
- Explanation:
- The number 5 as "n1" is passed into the local variable "a"
- The number 7 as "n2" is passed into the local variable "b"
- The function performs the multiplication & assigns the answer to the function name
- When the function ends, the value of 35 is returned to the calling statement
- Test it
- You may also call a function by using it inside another function:
MsgBox n1 & " x " & n2 & " = " & mult2Numbers(n1, n2)
- You may also call a function by using it as part of a Boolean comparison (decision or loop):
If mult2numbers(n1, n2) > 20 Then
MsgBox "Larger"
Else
MsgBox "Smaller"
End If
- Important: A function will return ONE AND ONLY ONE result to the calling statement
- Doubly important: You MUST use the return from a function:
- On the right side of an equal statement
- Inside another sub-routine or function
- As part of a Boolean comparison (decision or loop)
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Another Reference: wikiversity.org - Functions and Subroutines in VB6
- Lab Assignment -
- Create a VB program "vbGCF" to use sub-routines to calculate the Greatest Common Denominator between two user-supplied numbers:
- Design the form as shown, two input textboxe objects named "txtNum1" & "txtNum2", one output label object named "lblOutput", & three command button objects named "cmdGCF", "cmdLCM", & "cmdExit"
- Variables:
Option Explicit
Dim lngNum1 As Long
Dim lngNum2 As Long
Dim lngStopAt As Long
Dim lngCount As Long
Dim strOutput As String
Dim lngGCF As Long
Dim lngLCM As Long
- Pseudocode for "Exit":
Confirm that the user really wants to exit
If yes, end
- Pseudocode for "GCF":
If txtNum1.text is a number
Populate variable intNum1 with the value in txtNum1.text
End if
If txtNum2.text is a number
Populate variable intNum2 with the value in txtNum2.text
End if
Call a sub-routine to find the GCF
Call a sub-routine to displayOutput
- Pseudocode for "findGCF":
Populate variable intStopAt with the larger of intNum1 or intNum2
Loop from 2 to half of intStopAt
If intNum1 is evenly divisible by the sentinel variable AND
If intNum2 is evenly divisible by the sentinel variable THEN
' Remember the sentinel as a possible GCF
Populate variable intGCF
End if
End loop
- Pseudocode for "displayOutput":
Populate variable strOutput with appropriate content
Display strOutput onto lblOutput.caption
- Pseudocode for "LCM":
If txtNum1.text is a number
Populate variable intNum1 with the value in txtNum1.text
End if
If txtNum2.text is a number
Populate variable intNum2 with the value in txtNum2.text
End if
Call a sub-routine to find the LCM
Call a sub-routine to displayOutput
- Pseudocode for "findLCM":
Populate variable intStopAt with the product of intNum1 times intNum2
Loop from intStopAt to 1 decrement by -1
If the sentinel is evenly divisible by both intNum1 AND intNum2 then
Populate variable intLCM with the sentinel value
End if
End loop
|
| 32 |
10/22/07 |
|
Monday - VB Functions, "vbPower" |
|
- Classroom Discussion -
- Student Photos - 9:45 & 12:45
- Vocabulary:
- Recursion - A method of defining functions in which the function being defined is applied within its own definition
- Exponent - A number that indicates the operation of repeated multiplication
- Power - A number that indicates the operation of repeated multiplication
- math.com - explanation of exponents
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 13 - Modular Programming
- Lab Assignment -
- Visual Basic Quiz 3. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Create a Visual Basic program "vbPower.vbp" to raise a number to a power:
- Design the form with three textbox objects: "txtNum", "txtExp", & "txtOut" & two command button objects "cmdGo" & "cmdExit"
- Write the code for "cmdExit"
- Variables:
Option Explicit
Dim intNum As Integer
Dim intExp As Integer
Dim lngAns As Long
Dim strOut As String
Dim blnOk As Boolean
- Pseudocode for "cmdGo":
Set variable "blnOk" to true
Assign the result of function "getNum()" to variable "intNum"
Assign the result of function "getExp()" to variable "intExp"
if blnOk then
Assign the result of function "getAns(intNum, intExp)" to variable "lngAns"
end if
Call sub-routine "displayAns"
- Pseudocode for function "getNum() as Integer":
If "txtNum" is not a number
Display an appropriate error message
Set the focus
Set variable "blnOk" to false
Set the function to return a -1
Else
Set the function to return the value in "txtNum"
End if
- Pseudocode for function "getExp() as Integer":
If "txtExp" is not a number
Display an appropriate error message
Set the focus
Set variable "blnOk" to false
Set the function to return a -1
Else
Set the function to return the value in "txtExp"
End if
- Pseudocode for function "getAns(n as Integer, e as Integer) as Long":
If e - 1 then
Return n
Else
Return the results of function "getAns(n, e - 1)"
End if
- Pseudocode for sub-routine "displayAns():
If blnOk is true then
Build variable "strOut" as something like "Num raised to the power of Exp is Ans"
Else
Build variable "strOut" as something like "Error on input, please try again"
End if
- Write the code to select the contentes of the input textbox objects on "gotFocus()"
- Test with these numbers:
| number |
exponent |
answer |
| 3 |
3 |
27 |
| 8 |
2 |
64 |
| 2 |
8 |
256 |
| 5 |
4 |
625 |
| 4 |
5 |
1024 |
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
|
| 33 |
10/23/07 |
|
Tuesday - VB Functions, "vbNames" |
|
- Classroom Discussion -
- Visual Basic Listbox Object
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 10 - List Boxes and Data Lists
- Lab Assignment -
- Create a Visual Basic program "vbNames.vbp" to work with the Listbox object
- Design the form as shown
- 2 textbox objects named "txtUserName" & "txtIndex" for input
- 1 listbox object named "lstUserName" for output
- 4 command button objects named "cmdExit" & "cmdAddUser" & "cmdClearName" & "cmdDisplayOne"
- Code "cmdExit"
- Pseudocode for "cmdAddUser":
If validEntry() then
Add the value from the input textbox to the listbox
Clear the input textbox "txtUserName"
Set the focus to "txtUserName"
End If
- Pseudocode for function "validEntry()":
If the input is blank then
Display an appropriate error message
Set the focus to the input
Return False
ElseIf the input contains blank spaces
Display an appropriate error message
Set the focus to the input
Return False
Else
Set the focus to the input
Return True
End If
- Pseudocode for "cmdClearNames:
If vbYes then
Clear the user name listbox
Set the focus to the input
End If
- Pseudocode for "cmdDisplayOne":
If "txtIndex.text" is not numeric then
Display an appropriate error message
Set the focus
Else
Set variable "intIndex" to the value in textbox "txtIndex.text"
If variable "intIndex" is larger than the total number of items in the listbox then
Display an appropriate error message
Set the focus to "txtIndex"
Else
Display only that index item from the listbox in a message box
("lstUserName.List(intIndex)")
Set the focus to "txtIndex"
End If
End If
- After displaying the item from the listbox, clear the input & set the focus
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- When the user clicks on a username in the listbox, display a warning message, if the user answers "Yes", remove that one item from the listbox
- Modify the Listbox program to include a list of passwords
- Add another input textbox "txtPassword"
- Add another listbox "lstPassword"
- Both name & password may not be empty when using "cmdAddUser"
- "cmdDisplayOne" must display both name & password in a single message box
- Clear command button must clear both name & password listboxes
|
| 34 |
10/24/07 |
|
Wednesday - Career, VB Functions, "vbStates" game |
|
- Classroom Discussion -
- Guest Speaker - DeVry - 8:30 & 11:00 - Postponed
- Career - U.S. Federal Bureau of Labor Statistics website. The Bureau of Labor Statistics (BLS) is the principal fact-finding agency for the Federal Government in the broad field of labor economics & statistics
- Visual Basic Combobox Object
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 10 - List Boxes and Data Lists
- Useful VB Combobox methods:
- cboName.AddItem strItemName ' Add an item to the list
- intIndex = cboName.ListIndex ' Save the index number of the item that was clicked
- cboName.ListIndex = intIndex ' Select (highlight) the item using an index number
- Reading from a text file:
- Must be in the same folder (save, close, open your VB project)
- Name the file, close any open files, ensure the file exists & has data, open the file, like this:
- Lab Assignment -
- Programming Completer Pre-Exam. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Create a Visual Basic program "vbStates.vbp" to list all 50 U.S. states in a Combobox:
- Create a text file named "states.txt" with the names of all 50 U.S. states, Google search, copy & paste into notepad
- Create a text file named "capitals.txt" with the names of all 50 U.S. capitals, Google search, copy & paste into notepad
- Add a command button object & code to exit
- Add a combobox object "cboStates" to contain the list of the states
- Add a combobox object "cboCapitals" to contain the list of the capitals
- Add a label object "lblOut" for output
- Variables:
Option Explicit
Dim strLine As String
Dim strFileName As String
Dim strState As String
Dim strCapitalReal As String
Dim strCapitalPick As String
Dim intIndex As Integer
- Pseudocode for "Form_Load()", double-click any blank area of the form
Populate the variable "strFileName" with the name of the text file "states.txt"
Close any open files with "Close"
If the text file is not empty then
Open the text file for input
While not end of file
Read 1 line of data into variable "strLine"
Add the value in variable "strLine" to the combobox "cboStates"
Loop
End If
Repeat for file "capitals.txt" & combobox "cboCapitals"
- VB Code to open a non-empty text file for input:
If LenB(Dir$(strFileName)) Then ' file is not empty data
Open strFileName For Input As #1 ' open the file
End If
- VB Code to loop while not end of file:
Do While Not EOF(1)
' statements
Loop
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Pseudocode for "cboStates_Click()":
If the user clicks on a state then
Select the appropriate capital
Display an appropiate message on the output label
End If
- Pseudocode for "cboCapitals_Click()":
If the user clicks on a capital then
Select the appropriate state
Display an appropiate message on the output label
End If
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Add another combobox object named "cboCapitalsSorted", set the sorted property to True
- Add a checkbox object named "chkPlay"
- Modify the "Form_Load()":
Set "cboCapitals.Visible" = True
Set "cboCapitalsSorted.Visible" = False
Set "cboCapitals.TabStop" = True
Set "cboCapitalsSorted.TabStop" = False
Set "chkPlay.Value" = vbUnchecked
Set "cmdGuess.Visible" = False
- Pseudocode for "chkPlay_Click()":
If chkPlay.Value is vbChecked Then
Set "cboCapitals.Visible" = False
Set "cboCapitalsSorted.Visible" = True
Set "cboCapitals.TabStop" = False
Set "cboCapitalsSorted.TabStop" = True
Set "cmdGuess.Visible" = True
Else
Set "cboCapitals.Visible" = True
Set "cboCapitalsSorted.Visible" = False
Set "cboCapitals.TabStop" = True
Set "cboCapitalsSorted.TabStop" = False
Set "cmdGuess.Visible" = False
End If
- Pseudocode for "cmdGuess_Click()":
Populate variable "strState" with the selected item from "cboStates"
Populate variable "strCapitalReal" with the selected item from "cboCapitals"
Populate variable "strCapitalPick" with the selected item from "cboCapitalsSorted"
If strCapitalReal = strCapitalPick Then
Display an appropriate message on the output label caption
Else
Display an appropriate message on the output label caption
End If
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- If the checkbox is clicked, don't display matching answers
|
| 35 |
10/25/07 |
|
Thursday - English, OCC Information Session, VB Functions, "vbStates" game |
|
|
| 36 |
10/26/07 |
|
Friday - Skills USA, Visual Basic Quiz, "vbAreaPerimeter" |
|
- Classroom Discussion -
- PDP Intro
- Visual Basic Quiz in lab
- Lab Assignment -
- Visual Basic Quiz 4. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Quiz Part II - Design, write, create, test, run, & save a Visual Basic program called "vbAreaPerimeter" to display the area & perimeter of a rectangle
- Perimeter is found as the sum of twice the length plus twice the width
- Area is found as the product of length times width
Review the formulas necessary:
Design the form:
- 2 input text boxes: one for height, one for width
- A label with instructions
- A label for the answers
- Labels to identify all text boxes & any output labels
- 2 command buttons: one for exit, one for calculate
Guidelines:
- Declare variables for height & width & area & perimeter
- When the user clicks on exit, unload me
- When the user clicks on calculate, calculate the area & perimeter & display the values
- If the two input text boxes are numeric, convert the values & save into height & width variables
- Multiply height times width & put the answer into area
- Add height plus height plus width plus width & put the answer into perimeter
- Display both answers with appropriate descriptive text on the form
Finishing Up:
- Test with the numbers given
| Height |
Width |
Area |
Perimeter |
| 3 |
4 |
12 |
14 |
| 4 |
5 |
20 |
22 |
| 5 |
5 |
25 |
20 |
- If rectangle is a square, display some message saying so
- If you have time remaining, make the form look good - colors - font face & size - object placement - organization
- When all complete, copy the folder to your "Z:/toBeGraded/" folder so I can grade it
Grading (total of 100 pts available):
- Must give correct answers (75 pts)
- Must use Option Explicit (5 pts)
- Must use correct object & variable naming conventions (txtSomething & intSomething) (5 pts)
- Must have at least one programmer-written function or sub-routine (5 pts)
- Must have author name, program name, & date written as comments (5 pts)
- Must look good (5 pts)
- If you complete "vbArea", modify it to add other shapes:
These two-dimensional shapes can have perimeter & area values:
- Circle
- Triangle
- Rectangle
These three-dimensional shapes can have surface & volume values:
- Sphere (ball)
- Cone (ice-cream)
- Triangle Pyramid (Tetrahedron with four equilateral triangle faces)
- Rectangle Pyramid (Square base with four triangle faces)
- Octahedron (8 equilateral triangle faces)
Find the necessary formulas on the websites listed:
Guidelines:
- Modify the form with textboxes, labels, & command buttons
- Add any variables you might need
- Run the correct formulas
- Display appropriate output messages with your answers
|
|
| 37 |
10/29/07 |
|
Monday - Vocabulary, VB Option Buttons, "vbPong" |
|
- Classroom Discussion -
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 11 - Timer Object
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 18 - Image Object
- Pong - the first-ever computer video game:
- Lab Assignment -
- Create a Visual Basic program "vbPong.vbp", our own version of the first-ever computer video game:
- Create a new VB executable
- Name the form "pong" & change the caption to "Pong -The First-Ever Computer Video Game"
- Find a ball-shaped image online (I'll copy mine to the "Q:/pcProgramming/vbExamples" folder)
- Add an image object named "imgBall"
- Add two (2) line objects named "linLeft" & "linRight"
- Add two (2) label objects for score output named "lblLeft" & "lblRight"
- Add a timer object named "tmrBall"
- The timer interval property is measured in milliseconds
- There are 1000 milliseconds in a computer second
- To get the timer event to execute 10 times every second, 1000 clicks per second divided by 100 is 10 times
- NO NO NO == Add & code an exit command button object "cmdExit" == NO NO NO
KeyPress doesn't work if you have ANY command button objects
- Variables:
Option Explicit
Dim blnMoveUp As Boolean
Dim blnMoveLeft As Boolean
Dim intScoreLeft As Integer
Dim intScoreRight As Integer
- Pseudocode for Form_Load():
Set the form backcolor
Set the initial ball left property position to 199
Set the initial ball top property position to 199
Load the ball image into the ball picture property
Set the timer interval property to 100
Set the variable blnMoveUp to False
Set the variable blnMoveLeft to False
- Test
- Movement:
- Move the ball to the right by increasing the left property
- Move the ball to the left by decreasing the left property
- Move the ball down by increasing the top property
- Move the ball up by decreasing the top property
- Test
- Experiment with both "tmrBall.interval" & "imgBall.left" to get the smoothest movement
- Switch the ball movement whenever the ball "touches" an edge of the form:
- Pseudocode for moving ball left, right, up, & down:
If ball.left < 0 Then
Increment score right
Display right score
Move ball right
ElseIf ball.left + ball.width > form.width Then
Increment score left
Display left score
Move ball left
End If
If ball.top < 0 Then move ball down
If ball.top + ball.height > form.height Then move ball up
- Test
- Add two line objects named "linLeft" & "linRight"
- Modify the Form_Load():
' X1,Y1 is the top point of a line
' X2,Y2 is the bottom point of a line
Set the left line "X1" property to 100 from the left side of the form
Set the left line "Y1" property to 0 to match the form top
Set the left line "X2" property to 100 from the left side of the form
Set the left line "Y2" property to 1000 to make the line 1000 twips long
Set the right line "X1" property to the form width - 200
Set the right line "Y1" property to 0 to match the form top
Set the right line "X2" property to the form width - 200
Set the right line "Y2" property to 1000 to make the line 1000 twips long
- Locate the Form_Load() code & select "KeyPress" from the top-right dropdown menu
- We can move the paddles (left & right line objects) by pressing on keys
- We have to move both "Y1" & "Y2" at the same time
- Keep "Y2" the same distance from "Y1"
- Pseudocode for Form_KeyPress(KeyAscii As Integer):
If the user presses key #27 ("esc") then end
If the user presses key #101 ("E") then move the left paddle up 200
If the user presses key #100 ("D") then move the left paddle down 200
If the user presses key #105 ("I") then move the right paddle up 200
If the user presses key #107 ("K") then move the right paddle down 200
- Test
- If the ball hits either left or right paddle, change the direction, pseudocode:
If the ball is moving left AND
the left side of the ball is further less than the left paddle X1 AND
the middle of the ball (ball top + 1/2 ball height) is greater than the top of the left paddle Y1 AND
the middle of the ball is less than the bottom of the left paddle Y2 THEN
Change the ball direction
ElseIf the ball is moving right AND
the right side of the ball is further greater than the right paddle X1 AND
the middle of the ball (ball top + 1/2 ball height) is greater than the top of the right paddle Y1 AND
the middle of the ball is less than the bottom of the right paddle Y2 THEN
Change the ball direction
End If
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Add a feature to end play when either player reaches a score of 5 points
- Add a reset button & code
- Change the image from a smiley face to a frowny face when the image hits either wall
- Change the image each time the image changes direction (left or right)
|
| 38 |
10/30/07 |
|
Tuesday - English, Finish "vbPong" |
|
|
| 39 |
10/31/07 |
|
Wednesday - Happy Halloween - Career, VB Scrollbars, "vbQuotes" |
|
- Classroom Discussion -
- Review learning styles from Chaminade College Preparatory School
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 10 - Data Arrays
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 11 - Scrollbars
- Lab Assignment -
- Why take a completer exam before we learn?
- Compare your Fall score with your Spring score to discover how much you've learned
- Comprehend your opportunity to enrich your knowledge by being present & paying attention
- Receive the points you achieve as extra credit
- Anybody who achieves a 93% or above will receive an "A" for the course & is not required to complete any labs (attendance is still required)
- The database failed, take the test again
- Programming Completer Pre-Exam. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Take both of the following online learning styles assessments & write down your learning styles
- University of Arizona
- Record your answers in a table like this: (Here's what I got)
|
ArizonaU |
| Visual |
45 |
| Auditive |
17 |
| Kinestetic |
45 |
- Now that you know how you learn best, will you change the way you study?
- Create a Visual Basic program "vbQuotes" project to display various famous quotes with the user using scrollbars:
- How it works:
- The program pre-loads 5 famous quotes into an array variable
- The user changes the scroll bar
- The scroll bar value property determines which quote is displayed on an output label
- Design the form:
- A title
- A horizontal scroll bar object named "hsbQuote" with these initial properties:
- Min = 1
- Max = 20
- SmallChange = 1
- LargeChange = 1
- An output label object named "lblNum" to display the value of the scroll bar
- An output label object named "lblOut" to display the quote selected
- An exit command button object named "cmdExit" to exit
- Global Variables:
Option Explicit
Dim strQuote(20) As String
- Pseudocode for "Form_Load()":
Load string literals into each quote ' strQuote(1) = "First Quote"
Display the number 1 onto "lblNum" ' lblQuoteNumber.Caption = 1
Display the first quote onto "lblOut" ' lblOut.Caption = strQuote(1)
- Pseudocode for "hsbQuote_Change()":
Place the current scroll bar value onto "lblNum" ' lblNum.Caption = hsbQuote.Value
Place the current quote onto "lblOut" ' lblOut.Caption = strQuote(hsbQuote.Value)
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Use option (radio) buttons to control quote colors
- Use option (radio) buttons to control font names
- Use option (radio) buttons to control font styles (bold & italic)
- Use another scroll bar to control font size
- Modify your distance and/or temperature converter programs to use scrollbars to input the distance or temperature
- Complete any unfinished assignments
|
| 40 |
11/01/07 |
|
Thursday - DeVry, Completer Pre-Exam, modify "vbQuotes", modify "vbTrafficLight" |
|
- Classroom Discussion -
- Lab Assignment -
- Why take a completer exam before we learn?
- Compare your Fall score with your Spring score to discover how much you've learned
- Comprehend your opportunity to enrich your knowledge by being present & paying attention
- Receive the points you achieve as extra credit
- Anybody who achieves a 93% or above will receive an "A" for the course & is not required to complete any labs (attendance is still required)
- The database failed, take the test again
- Programming Completer Pre-Exam. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Modify your "vbQuotes" project to allow the user more control by using timers
- Add a timer object named "tmrQuote" that will automatically change the quote after a set amount of time has expired
- Set the timer interval to 5000 ticks
- Write the code for the timer object to call the next quote command button when the time expires
- Save & Test
- Change the timer enabled property to False
- Add a checkbox object "chkTimer" & code to enable the timer when checked
- Save & Test
- Add a variable "intTimer" started at 5 that will count down to changing the quote
- Add a label "lblTimer" to display the "intTimer"
- Change the timer interval to 1000 ticks
- Change the code inside the timer object to test the value of "intTimer", if intTimer <= 0 then call the next quote command button & set "intTimer" back to 5, else decrement "intTimer"
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Think up & do something I didn't think of
- Modify your "vbLight" traffic light program to automatically change the lights, say 20 seconds red, 15 seconds green, & 5 seconds yellow
- Complete any unfinished assignments
|
| 41 |
11/02/07 |
|
Friday - Daylight Saving Time Ends Sunday, SkillsUSA, "vbImageDisplayer2" |
|
- Classroom Discussion -
- Daylight Saving Time - Remember to change your clocks
- Lab Assignment -
- Create a VB program "vbImageDisplayer2" to display a series of images using an image, a timer, a scrollbar, & a checkbox:
- Open VB, make a new executable, name the form, save into a folder, & close VB
- Open Windows Explorer ("My Documents" or "My Computer"), browse to the folder, & open the project by double-clicking
- Add & code an Exit command button object
- Add an image or picture object to display your images
- Search for & copy about 10 images off the internet & save them into the correct folder
- Load the names of the images from a text file into a data array variable so you can display them in a timer loop
- Add & code a timer object to control switching the image automatically
- WARNING - Be careful to not let the index to the data array go down past zero or up past the maximum number of images used
- Add & code a scrollbar object to control the timer interval, how long an image is displayed before it switches
- Add & code a checkbox object to control whether the timer is enabled True or False
- Add & code a label object to display the name of the current displayed image
- Save & test
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Add objects for "Back" & "Forward" buttons & allow the user to select whether to use the auto-timer or the buttons
- Complete any unfinished assignments
|
|
| 42 |
11/05/07 |
|
Monday - Visual Basic Quiz, "vbOhmsLaw", "vbSnake" |
|
- Classroom Discussion -
- Check your grades - if you haven't completed an assignment, you may complete it this week
- Online VB6 Text: Sams Teach Yourself Visual Basic 6 - Chapter 18 - Animating Pictures
- the12volt.com - Formulas for Ohm's Law
- msdn2.microsoft.com - Visual Basic Math Functions
- Lab Assignment -
- Visual Basic Quiz 5. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
- Quiz Part II - Design, write, create, test, run, & save a Visual Basic program called "vbOhmsLaw" to allow the user to calculate the Power laws:
- Open Visual Basic & create a new executable
- Name the form "frmOhmsLaw" & name the project "vbOhmsLaw"
- Design the form to let the user choose which calculation to use
- Design the form to let the user input 2 numbers
- Process the correct calculation(s) & display the answer(s)
- Use the pre-defined, built-in, VB function dblAns = Math.Sqr(dblNum) to calculate square roots
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
|
| 43 |
11/06/07 |
|
Tuesday - "vbSnake" cont'd |
|
- Classroom Discussion -
- the grades spreadsheets is done:
- Navigate to your "Z:/Grades" folder
- Double-click the "css##.csv" (comma-separated-variable) file using Microsoft Excel
- Review the file for assignments due & completed
- The top left 5 rows & 3 colums have your name, css##, & summary grade
- Columns "A" through "D" are lab assignments (1/3 of total grade)
- Column "A" is the date an assignment was assigned
- Column "B" is the assignment name
- Column "C" (Points Assigned) is the max points you can receive for any assignment
- If Column "C" is blank, the assignment is extra credit
- Column "D" (Points Achieved) is the grade you received for the assignment
- If Column "D" is blank, either you haven't completed the assignment or I haven't graded it
- Column "D" is usually ranked on a scale of 0 to 100 with 75 being average
- Columns "B" through "D" rows 106 through 110 show any extra credit received, assignments due & completed
- You may complete & hand-in (toBeGraded) any incomplete or ungraded assignment up until the end of the marking period
- Columns "E" through "H" are attendance/participation (2/3 of total grade)
- Column "E" is the date
- Column "G" (Attendance Assigned) is the max points you can receive for any attendance/participation
- If Column "G" is blank, no points available, usually means school closed
- Column "H" (Attendance Achieved) is the grade you received for the attendance/participation
- Columns "H" through "H" are attendance/participation (2/3 of total grade)
- Column "H" is on a scale of 0 to 4, blank or 0-absent, 1-present but no participation, 2-present with some participation, 4-present with total participation
- In Column "H" an "x" means excused absence, with 4 extra points given in leu of actual attendance
- Columns "F" through "H" rows 63 through 67 show attendance/participation summary
- Any questions?
- Lab Assignment -
- Create a Visual Basic program "vbSnake" to play the famous cell phone game:
- Rules:
- The "snake" will start with a length of 5
- The "snake" will start moving at 10 spaces each second (timer interval = 100)
- The "food" will appear randomly & last for 5 seconds
- Each time the "snake" eats the "food" ("snake-head" top & left equal "food" top & left) the "snake" grows & adds 5 additional segments
- The length of the "snake" will never exceed 50 segments
- The speed will appear to increase when the "snake" feeds (decrease timer interval)
- The speed will never exceed light-speed
- The game ends when the "snake" encounters a wall ("snake-head" top & left pass outside the game field)
- The game ends when the "snake" encounters part of its own body ("snake-head" top & left equal part of the "snake" body)
- The number of "foods" the "snake" has eaten will appear on a label on the form
- Create a new Visual Basic executable
- Design the form with sufficient controls & objects
- Add a Shape object "shpBoard" for the game board
- Add a Shape object "shpHead" for the head of the snake
- Add a Shape object "shpFood" for the food
- Add a Timer object "tmrHead" to control snake head movement
- Add a Label object "lblScore" to display the score
- Add a Label object "lblFoodTime" to display the food time
- Write the code
- In the Form_Load(), set the board, snake head, & food initial height/width sizes & top/left positions
- Remember - in order to make it look good, start the snake head at a multiple of the width & height of the snake head: if the snake head is 250 wide & 250 high, start the snake head at 1000 & 1000
- Remember - in order to make it look good, move the snake in multiples of the snake head width & height: 250
- Use an integer variable "intDir" to keep track of direction (1=up, 2=down, 3=left, 4=right)
- On keyDown, use a Select Case to determine which key was pressed & change direction variable:
- 56 is up (8) on the number keypad
- 50 is down (2) on the number keypad
- 52 is left (4) on the number keypad
- 54 is right (6) on the number keypad
- In the food timer:
- Randomly place food on board
- Keep the food visible for 10 seconds
- Whenever the snake head overlaps the food (.top & .head) it is considered eaten
- Move uneaten food to another location every 10 seconds
- In the snake head timer:
- Use a Select Case to control direction
- Test for snake head overlap food & increment score & display score & move food & restart food timer
- Test for snake head position on board or over board
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive
- Complete any unfinished assignments
|
| 44 |
11/07/07 |
|
Wednesday - "vbSnake" Cont'd |
|
- Classroom Discussion -
- Lab Assignment -
- Visual Basic program "vbSnake", cont'd
- Use "My Documents" or "My Computer" to navigate to & open your existing Visual Basic "vbSnake" program
- Copy the snake head & name it "shpTail"
- Copy the snake tail & paste it creating a Control Array of "shpTail()", create a total of 50 tail segments
- In the Form_Load(), in a loop, reset all "shpTail(i)" top/left/width/height/shape/visible properties
- Add a variable "intTailLength" to control the length of the tail & initialize it to 5 in the Form_Load()
- In a loop at the end of the timer, set top/left of each active (visible) tail segment to the top/left of the previous tail segment. When the snake head is moving, the tail will follow it like a centipede tail follows the centipede head -- snaking forward
- If the snake head hits one of the tail segments, game over
- When the snake head eats food, increment the tail length by 5 & decrement the timer interval by 20
- Test & Save frequently Save to your "My Documents" folder & copy to your "Z:" drive & copy to your "Z:" drive
- Complete any unfinished assignments
|
|
11/08/07 |
|
Thursday -
OCVTS School Closed - NJEA Convention |
|
11/09/07 |
|
Friday -
OCVTS School Closed - NJEA Convention |
|
| 45 |
|
|
|
|
|
| 46 |
|
|
|
|
|
| 47 |
|
|
|
|
|
| 48 |
|
|
|
|
|
| 49 |
|
|
|
|
|
|
|