Matrix (math) - Rectangular array of
numeric or algebraic quantities subject to mathematical operations
Matrix (computers) - Network of
intersections between input and output leads in a computer,
functioning as an encoder or a decoder
Matrix (anatomy) - Formative cells or
tissue of a fingernail, toenail, or tooth
Matrix (geology) - Solid matter in which a
fossil or crystal is embedded
Array (verb) - Set out for display or use; dress in finery
Array (nown) - Orderly, imposing arrangement; an impressively large
number of persons or objects
Array (math) - Rectangular arrangement of quantities in rows and
columns, as in a matrix
Array (computer) -
An arrangement of memory elements
Cypher (noun) - Cryptographic system in
which units of plain text of regular length, usually letters, are
arbitrarily transposed or substituted according to a predetermined code
Declare an array: Dim arrayName(integerNumber) as dataType
Initialize an array in a loop: arrayName(sentinelVariable) =
someValue
Use an array in a loop: msgbox
arrayName(sentinelVariable)
Two-Dimensional Arrays -
Declare a two-dimensional array: Dim arrayName(intNum1, intNum2)
as dataType
Initialize a two-dimensional array in a loop:
arrayName(intSent1,intSent2) = someValue
Use a two-dimensional array in a loop: msgbox
arrayName(intSent1,intSent2)
Lab Assignment -
Visual Basic practice program "vbMatrix" -
create a demo program using two 2x2 matrices & perform the math we
learned today
Create a new standard exe "frmMatrix" & "vbmatrix"
Add & code a command button to exit
Add a picture box for output
Add & code a command button to clear the output picture box
In the Global section at the top, add two array variables to represent two 2x2 matrices:
Dim matOne(1, 1) As Integer
Dim matTwo(1, 1) As Integer
In the Global section at the top, create other variables as needed:
Dim intRow, intCol, intCount As Integer
In the Form_Load(), write code to initialize both matrix arrays with known numbers:
intCount = 1
For intCol = 0 To 1
For intRow = 0 To 1
matOne(intCol, intRow) = intCount
matTwo(intCol, intRow) = intCount + intCount
intCount = intCount + 1
Next intRow
Next intCol
Add & code a command button to show the contents of both matrix arrays:
picOutput.Print "Matrix One Matrix Two"
For intCol = 0 To 1
For intRow = 0 To 1
picOutput.Print matOne(intCol, intRow);
Next intRow
picOutput.Print " ";
For intRow = 0 To 1
picOutput.Print matTwo(intCol, intRow);
Next intRow
picOutput.Print
Next intCol
Add & code an add button to add the two matrix arrays & display the result:
picOutput.Print "Addition Results:"
For intCol = 0 To 1
For intRow = 0 To 1
picOutput.Print matOne(intCol, intRow) + matTwo(intCol, intRow);
Next intRow
picOutput.Print
Next intCol
Add & code an subtract button to subtrace the two matrix arrays & display the result:
picOutput.Print "Subtraction Results:"
For intCol = 0 To 1
For intRow = 0 To 1
picOutput.Print matOne(intCol, intRow) - matTwo(intCol, intRow);
Next intRow
picOutput.Print
Next intCol
Add & code a multiply button to multiply both matrix arrays by 2 & display the result:
picOutput.Print "Scale by 2 Results:"
picOutput.Print "Matrix One Matrix Two"
For intCol = 0 To 1
For intRow = 0 To 1
picOutput.Print 2 * matOne(intCol, intRow);
Next intRow
picOutput.Print " ";
For intRow = 0 To 1
picOutput.Print 2 * matTwo(intCol, intRow);
Next intRow
picOutput.Print
Next intCol
Visual Basic program "vbCypher" - create a simple offset replacement cypher using a single one-dimensional array:
Statement of use: this program will create a simple cypher by using offset replacement to replace uppercase alphabetic characters from "A" to "Z" with other uppercase alphabetic characters. Numbers, punctuation, spaces, & other special characters will not be changed
Specifications & requirements:
The user will enter a phrase to be encyphered into a large textbox
The user will enter a number between 1 & 26 to represent the offset amount into a second textbox
The offset number may not be zero -- this would create an encyphered message that reads exactly like the original
The user will click a command button to perform an encoding process
The encoding process will take each alphabetic letter from the input & replace it with an alphabetic letter offset by the offset number
If the offset is 1: ABC would be encyphered as BCD
If the offset is 5: ABC would be encyphered as FGH
If the offset is 10: ABC would be encyphered as KLM
If the offset is 3: XYZ would be enchphered as ABC
If the offset is 5: XYZ would be enchphered as CDE
Use all uppercase letters
Do not encypher numbers or punctuation or spaces or other special characters
The output will be displayed in a large output label
There will be a command button to clear the output label
There will be a command button to clear the input textbox
There will be a command button to exit
Create the program:
Create a new standard exe "frmCypher" & "vbCypher"
Add & code a command button to exit
Add a large textbox for input of a sentence or paragraph to be encoded & set the multiline property to true
Add a textbox for input of offset number
Add a large output label to display the results of the encoding
Add & code a command button to clear the output label
Add & code a command button to clear the input textbox & set the focus
Add an array variable "strAlphabet()" with 26 positions as datatype string & initialize in Form_Load() with 26 uppercase letters of the alphabet
For i = 1 To 26
strAlphabet(i) = Chr(i + 64)
Next i
Add & code a command button to code the input text & display the result on the output label:
Convert the offset text to a number only if it is numeric:
If IsNumeric(txtOffset.Text) Then
intOffset = CInt(txtOffset.Text)
Otherwise display an error message
Perform the process only if the input textbox is not empty:
If Not IsEmpty(txtInput.Text) Then
Otherwise display another error message
Determine the length of the input box because you must look at & convert every alphabetic character:
intInputLength = Len(txtInput.Text)
For i = 1 To intInputLength
Get one letter & convert it to an ASCII number:
strChr = Mid(txtInput.Text, i, 1)
intAsc = Asc(strChr)
If the letter is lowercase, ASCII 97 - 122, convert it to uppercase:
If intAsc >= 97 And intAsc <= 122 Then intAsc = intAsc - 32
If the letter is an uppercase alphabetic letter, ASCII 65 - 90, change it by the offset number:
If intAsc >= 65 And intAsc <= 90 Then
intAsc = (intAsc - 64) + intOffset
If the result of adding the offset number is greater than 26, start back at the beginning:
If intAsc > 26 Then intAsc = intAsc - 26
Display the offset character onto the output label:
Copy & modify the folder containing "vbCypher" to "vbCypher2" to encode all possible characters on the keyboard:
You don't need to declare the array "strAlphabet()", you may comment it out
You don't need to initialize the array "strAlphabet()" in the Form_Load(), comment it out
Modify the code in "cmdEncode" to work for all keyboard characters (ASCII 32 to 128):
For i = 1 To intLen
strChr = Mid(txtInput.Text, i, 1) ' get one character from text to be encoded
intAsc = Asc(strChr) + intOffset ' convert to ASCII and add offset
If intAsc > 128 Then intAsc = intAsc - 96 ' check for wraparound
strChr = Chr(intAsc) ' convert to character
lblOutput.Caption = lblOutput.Caption & strChr ' add to output label
Next i
Modify the code in "cmdDecode" to work for all keyboard characters (ASCII 32 to 128):
For i = 1 To intLen
strChr = Mid(lblOutput.Caption, i, 1) ' get one character from text to be decoded
intAsc = Asc(strChr) - intOffset ' convert to ASCII and subtract offset
If intAsc < 32 Then intAsc = intAsc + 96 ' check for wraparound
strChr = Chr(intAsc) ' convert to character
lblDec.Caption = lblDec.Caption & strChr ' add to decode label
Next i
Modify the "vbCypher" program in folder "vbCypher2" to use higher-level ASCII code to really confuse 'em:
Modify the code in "cmdEncode":
'intAsc = Asc(strChr) + intOffset ' convert to ASCII and add offset
'If intAsc > 128 Then intAsc = intAsc - 96 ' check for wraparound
intAsc = Asc(strChr) + intOff + 128 ' convert to higher ASCII and add offset
If intAsc > 255 Then intAsc = intAsc - 128 ' check for wraparound
Modify the code in "cmdDecode":
'intAsc = Asc(strChr) - intOffset ' convert to ASCII and subtract offset
'If intAsc < 32 Then intAsc = intAsc + 96 ' check for wraparound
intAsc = Asc(strChr) - intOff - 128 ' convert to normal ASCII and subtract offset
If intAsc < 32 Then intAsc = intAsc + 96 ' check for wraparound
See if you can figure out a way to let the user choose which ASCII set to use (32-128 or 128-255)
QUIZ - Take the Visual Basic Quiz 5. Click the link and follow the instructions. PRINT AND HAND IN. 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 for help
QUIZ - Visual Basic Quiz program "vbLeet":
Design, write, create, test, run, and save a Visual Basic program to translate normal characters to "leet" - get ideas from this wikipedia page
Requirements:
Get the phrase to be translated from the user - textbox object
Display the results to the user - use a textbox object to allow the user to copy the result
Chapter 17 from samsPublishing.com - Connecting Menus to Event Procedures
Lab Assignment -
Create a storyboard to use to create a PowerPoint presentation about the Computer Science class:
Graded Assignment
Hand-Written
Single-Page
Name-on-it
Hand-in
Create a Visual Basic program "vbATM" to practice with Visual Basic menus:
Create a new VB executable "frmATM" and "vbATM" in a folder "vbATM"
Main Steps:
ATM can 1)Check Balance, 2)Deposit Money, 3)Withdraw Money
Create a text file to hold the current balance
Declare Variables
Initialize Variables
Open the File and Get Balance
Display the Balance
Deposit Money (add to balance and display)
Withdraw Money (subtract from balance and display)
Save File and Continue Working
Save File and Exit
Create a file "bankAccount.txt" with "0" (zero) as the only data in the folder "vbATM"
Open the Menu Editor - [ctrl+E] or Tools | MenuEditor
You must be in View | Object mode in order to be able to open the Menu Editor
Build the menu:
Add caption property "&File" and name property "mnuFile" - menu bar menu items don't get any code
Add indented caption "&Open" and name "mnuFileOpen" - pull down menu options will get coded
Add indented caption "-" and name "mnuFileSep1" - a single hyphen/dash draws a separater bar
Add indented caption "&Save" and name "mnuFileSave"
Add indented caption "-" and name "mnuFileSep2"
Add indented caption "e&Xit" and name "mnuFileExit"
Add caption "&ATM" and name "mnuATM"
Add indented caption "&Balance" and name "mnuATMBalance"
Add indented caption "-" and name "mnuATMSep1"
Add indented caption "&Deposit" and name "mnuATMDeposit"
Add indented caption "&Withdrawal" and name "mnuATMWithdrawal"
Add caption "&Help" and name "mnuHelp"
Add indented caption "&About" and name "mnuHelpAbout"
Close the MenuEditor by clicking [Okay]
Add a textbox object "txtAmount" to the form and label it
Let the Visual Basic Integrated Design Environment (VB-IDE) create the subroutine for you: click the form menu option
Declare your variables:
Option Explicit
Dim strBalance As String ' existing bank balance
Dim sngBalance As Single ' existing bank balance
Dim sngAmount As Single ' amount to add or withdraw
Dim blnFileOpen As Boolean ' flag variable to show whether file was open
Dim strFileName As String ' name of file
Write the code for the "Form_Load()" subroutine:
blnFileOpen = False ' initialize to file not open
strFileName = "bankAccount.txt" ' name of file
sngBalance = 0 ' initialize to 0
sngAmount = 0 ' initialize to 0
Write the code for the "mnuFileOpen" subroutine:
If LenB(Dir$(strFileName)) Then ' file has depth
Open strFileName For Input As #1 ' open the file to read
Line Input #1, strBalance ' get text balance from text file
sngBalance = CSng(strBalance) ' change to number
blnFileOpen = True ' file was opened
Close ' close any open files
Else
MsgBox "File " & strFileName & " not found" ' error message
End If
Write the code for the "mnuATMBalance_Click()" subroutine:
If blnFileOpen Then
MsgBox "Current Balance: " & sngBalance ' display current balance
Else
MsgBox "File " & strFileName & " is not open" ' file was never opened
End If
Write the code for the "mnuATMDeposit_Click()" subroutine:
If blnFileOpen Then ' if the file was opened
If IsNumeric(txtAmount.Text) Then ' check for numeric
sngAmount = CSng(txtAmount.Text) ' change text to number
sngBalance = sngBalance + sngAmount ' add to current balance
txtAmount.Text = "" ' clear amount so user doesn't have to
txtAmount.SetFocus ' set focus so user doesn't have to
Else
MsgBox "Deposit Amount Must be a Number" ' error message
End If
Else
MsgBox "File " & strFileName & " was not opened" ' file was not opened
End If
Write the code for the "mnuATMWithdrawal_Click()" subroutine:
If blnFileOpen Then ' if the file was opened
If IsNumeric(txtAmount.Text) Then ' check for numeric
sngAmount = CSng(txtAmount.Text) ' change text to number
If sngAmount < sngBalance Then ' check for available balance
sngBalance = sngBalance - sngAmount ' withdraw from current balance
txtAmount.Text = "" ' clear amount so user doesn't have to
txtAmount.SetFocus ' set focus so user doesn't have to
Else
MsgBox "Requested Withdrawal of " & sngAmount & " is greater than available balance of " & sngBalance
End If
Else
MsgBox "Withdrawal Amount Must be a Number" ' error message
End If
Else
MsgBox "File " & strFileName & " was not opened" ' file was not opened
End If
Write the code for the "mnuFileSave_Click()" subroutine:
If blnFileOpen Then ' if the file was opened
Open strFileName For Output As #1 ' open the file to write
Write #1, sngBalance ' write the balance
Close ' close any open files
Else
MsgBox "File " & strFileName & " was not opened" ' file was not opened
End If
Write the code for the "mnuFileExit_Click()" subroutine:
If blnFileOpen Then ' if the file was open
Open strFileName For Output As #1 ' open the file to write
Write #1, sngBalance ' write the balance
Close ' close any open files
End If
End ' end program run
Write the code for the "mnuHelpAbout_Click()" subroutine:
use randomize intSeed where intSeed is a number input in a textbox
to create a repeatable random number list with a different seed value
Lab Assignment -
Modify the "vbCypher" Visual Basic program to use random numbers to produce a cypher more difficult to decode and use it to encode/decode messages:
Create a new Visual Basic program "frmCypher" and "vbCypher" saved in folder "vbCypher3"
Add a large textbox for input of a normal or encoded phrase
Add a large textbox for output of an encoded or decoded phrase
Add menu options for:
Name
Caption
mnuFile
&File
mnuFileGetSeedNumber
&GetSeedNumber
mnuFileExit
e&Xit
mnuCypher
&Cypher
mnuCypherEncode
&Encode
mnuCypherDecode
&Decode
mnuCypherMove
&Move
mnuSecurity
&Security
mnuSecurityLowest
&Lowest
mnuSecurityNormal
&Normal
Check the "Checked" property for mnuSecurityNormal
mnuSecurityHighest
&Highest
Write the code for the variables:
Option Explicit
Dim i As Integer
Dim strSeed As String
Dim intSeed As Integer
Dim intRand As Integer
Dim intSecurity As Integer
Dim intLen As Integer
Dim intAsc As Integer
Dim strChr As String
Write the code for the "Form_Load()" subroutine
intSeed = 0
The next three work like a three-way radio-button where only one can be checked, when the user checks one the other two are unchecked
Write the code for the "mnuSecurityLowest_Click()" subroutine
Write the code for the "mnuSecurityHighest_Click()" subroutine
mnuSecurityLowest.Checked = False
mnuSecurityNormal.Checked = False
mnuSecurityHighest.Checked = True
End Sub
Write the code for the "mnuFileExit_Click()" subroutine
Unload Me
Write the code for the "mnuFileGetSeedNumber_Click()" subroutine
strSeed = InputBox("Enter Cypher Seed Number", , "5")
If IsNumeric(strSeed) Then
intSeed = CInt(strSeed)
Else
MsgBox "Cypher Seed Must be a Number"
End If
Write the code for the "mnuCypherEncode_Click()" subroutine
txtOutput.Text = "" ' clear the output box
Rnd -1 ' reset random number generator
Randomize (intSeed) ' reinitialize random number generator
If txtInput.Text <> "" Then
intLen = Len(txtInput.Text)
For i = 1 To intLen
strChr = Mid(txtInput.Text, i, 1)
intAsc = Asc(strChr)
If intAsc <> 32 Then ' not encode spaces
intRand = Int(Rnd() * 25) ' random number between 0 and 25
If mnuSecurityLowest.Checked Then intRand = 0
intAsc = intAsc + intRand
If intAsc > 127 Then intAsc = intAsc - 96
If mnuSecurityHighest.Checked Then intAsc = intAsc + 128
strChr = Chr(intAsc)
End If
txtOutput.Text = txtOutput.Text & strChr
Next i
Else
MsgBox "Please Enter Phrase to be Encoded"
End If
Write the code for the "mnuCypherDecode_Click()" subroutine
txtOutput.Text = "" ' clear the output box
Rnd -1 ' reset random number generator
Randomize (intSeed) ' reinitialize random number generator
If txtInput.Text <> "" Then
intLen = Len(txtInput.Text)
For i = 1 To intLen
strChr = Mid(txtInput.Text, i, 1)
intAsc = Asc(strChr)
If intAsc <> 32 Then ' not decode spaces
intRand = Int(Rnd() * 25) ' random number between 0 and 25
If mnuSecurityLowest.Checked Then intRand = 0
intAsc = intAsc - intRand
If intAsc < 32 Then intAsc = intAsc + 96
If mnuSecurityHighest.Checked Then intAsc = intAsc - 128
strChr = Chr(intAsc)
End If
txtOutput.Text = txtOutput.Text & strChr
Next i
Else
MsgBox "Please Enter Phrase to be Encoded"
End If
The next line is for testing: we have to make sure we can decode what we've just encoded using the same seed number
Write the code for the "mnuCypherMove_Click()" subroutine
Visual Basic code to READ FROM an input text file:
If LenB(Dir$(strFileIn)) Then ' file has depth
Open strFileIn For Input As #1 ' open the file to read
Input #1, intStopValue ' get sentinel data
Input #1, intOne, intTwo, intThree ' get data from input file
Visual Basic code to WRITE TO an output text file:
Open strFileOut For Append As #2 ' open the file to write
Write #2, intOne, intTwo, intThree, intSum ' write the data
The computer science class is part of the school's "Building Objective" this year. We are required to acquire basic skills in obtaining information, solving problems, thinking critically, and communicating effectively through vocational education. The objective is to, by June 2006, demonstrate an improvement in technology skills by developing a Microsoft PowerPoint presentation on a trade related skill project. I will create a rubric that measures completeness. You will create a Microsoft PowerPoint presentation as an advertisement for this class.
Project: Develop a computer presentation covering what the computer science class is all about, what we study and how, what we create, where students go after completing the course.
Step 1: Create a Storyboard using pencil/pen and paper. Use the web sites above for reference. Put your name on it and hand it in
Use Visual Basic to solve Problem 0 on the 2005 NJIT High School Programming Contest Problems page:
Create a Visual Basic program "frmNJITRaceTrack" and "vbNJITRaceTrack" in a folder "css##vbNJITRaceTrack"
Using a text file as a draft for different gameboard designs:
Using different board names: "board1.txt"
Input into an array variable
Draw the board from the array variable
Lab Assignment -
Create a Visual Basic program to simulate the historic arcade game of "Pac Man". One lone yellow dot, just trying to get by, increasing his score by eating all the other little dots, chased by red ghosts, able to chase and eat the blue ghosts after eating a "power pill":
"frmPacMan.frm" and "vbPacMan.vbp" in a folder "vbPacMan"
You may use my images or search for your own:
Specifications:
In order to be able to test movement and keep score, we'll use a base setting of 500 x 500 twips for all images
Create a gameboard on which the man and ghosts will move
The board will be a square shape made up of 11 x 11 smaller squares
The smaller squares will be 500 x 500 twips
This means the gameboard will be 5500 x 5500 twips so your form must be larger
Some of the smaller squares will be solid, as walls, through which no moving object may move
When the smaller square is not solid, a small yellow "food" dot will appear
Four (4) of these small "food" dots will be "power pills", signified by the color purple
The user will be able to choose from a minimum of four (4) different game boards which you will design
The user will pick a game board by pressing a number 1 - 4
The program will load a text file, i.e. "input1.txt", and then draw the smaller squares on the larger game board based on instructions containted in the text file
There are two types of moving objects: one (1) man, a yellow dot, and four (4) red or blue ghosts
The man will initially appear on the bottom row in the center square
The user will control the man's movement using the four (4) cursor keys, up, down, left, right
The man must run away from the red ghosts
The man must attempt to "eat" all of the small yellow "food" dots, worth 1 point each
If the man successfully "eats" all the "food", the man wins, and the user will be prompted "play again?"
The red ghosts will "eat" the man if their positions on the game board ever overlap
The man has three (3) lives, that is, if the man is "eaten" three times the ghosts win
There will be four (4) red ghosts and they will initially appear at the top row center square
The four ghosts will move randomly
Whenever the man eats a "power pill", the red ghosts will turn blue for an amount of time, probably 15 seconds
The man may "eat" blue ghosts and gain 10 points if their positions on the game board ever overlap
A blue ghost, once "eaten", will appear again at the top center as a red ghost
No moving object will move beyond the boundaries of the game board
No moving object will move through solid smaller squares
Ghosts may overlap other ghosts with no penalty
Game Board Pseudocode:
Create the form
Add a Shape object "shpBoard" background color black, border color black, border style opaque, border width 3, top, left, height=5500, width=5500
In the "Form_Load()" reset position properties of top, left, height, width
Save & Test
Add variables for intRow, intCol, intPlace
Add a Shape object "shpSquare" background color white, border color white, border style opaque, border width 3, top, left, height=500, width=500
Copy "shpSquare" and paste onto the form CREATE A CONTROL ARRAY
Paste a total of 121 of these smaller black squares (0 - 120)
In the "Form_Load()" add code to place all 121 "shpSquare" objects to their proper position on the board and reset their height and width to 500
Conjure math for positioning each small square (row and col):
There are 121 small squares (0 - 120)
intRow can go from 0 to 10
intCol can go from 0 to 10
How can you make 0 to 120 from 0 to 10 and 0 to 10???
Save & Test
Add a Shape object "shpFood" background color red, border color red, border style opaque, shape circle, border width 3, top, left, height=100, width=100
Copy "shpFood" and pase onto the form CREATE A CONTROL ARRAY
Paste a total of 121 of these small red dots (0 - 120)
Change the color to blue for the four corner dots (#0, 10, 110, 120)
In the "Form_Load()" add code to place all 121 "shpFood" objects to their proper position on the board and reset their height and width to 100 (use the existing loops)
Conjure math for positioning these objects onto the game board
Save & Test
Add code in the "Form_KeyDown()" to test for the escape key and then end the program
Save & Test
Add code in the "Form_KeyDown()" to test for the numbers between 1 and 4 to load a game board design
Create the four text files with the game board designs:
Each text file will have 11 rows of 11 "Xs" and "Os", separated by a comma (,)
The "X" signifying solid wall and the "O" signifying open
Make interesting patterns
Remember - the power pills will be in the four corners of the game board, so don't put a wall ("X") in the corners
Also, it's a bad idea to have dead ends or piazza where there are no walls at all
Create a subroutine "drawBoard(intFileNum as Integer)" to draw the board from the text file based on the key the user presses
Open the correct input file - you can concatenate the "intFileNum" to the "input.txt"
For each small square (row and col)
Read each character from the input file
Calculate which square it represents
If "X", show the square wall (visible=true) and hide the food (vislbie=false)
If "O", hide the square wall (visible=false) and show the food (vislbie=true)
Add a new global variable "intBoard" to hold which board was chosen and set it to -1 in the "Form_Load()"
Assign the board number to the variable "intBoard = intFileNum"
Call the subroutine "drawBoard()" from inside the "Form_KeyDown()" and remember to pass the correct file number
Save & Test
You may, it you desire, create up to ten (10) different game board designs (Why only 10?)
Use a Timer Object, when the time interval expires, the moving object moves
Remember which direction is being moved
Change the top or left property to move a certain distance
Check and stop at the edge of the game board BEFORE crossing the edge -- when the NEXT position would be outside the edge of the game board
Check and stop when encounter any non-moving object like a wall -- when the object in the NEXT position is visible=true
The user controls the object with the cursor keys: vbKeyUp, vbKeyDown, vbKeyLeft, vbKeyRight
Use a Select Case
Lab Assignment -
Modify the Visual Basic program "vbPacMan" to move the man and let the user control the moving the man:
The Man Pseudocode:
Create an Image Object "imgMan" with picture property "PacMan1.gif" and stretch property "True"
Place the man on the game board bottom center square in the "Form_Load()" event:
Top = top of board plus height of 10 small squares
Left = left of board plus width of 5 small squares
Height and Width = 500
Create a Timer Object "tmrMan" to control the man:
Enabled = False
Interval = 250
Add variables:
intManDir to hole the current man direction, 0 = up, 1 = down, 2 = left, and 3 = right
intManPos to hold on which small square the man currently is
intManNum to hold the number representing the man mouth size (2 = small, 3 = normal, 4 = large)
Add a case statement to the "Form_KeyPress()" to evaluate the keystroke "G" for GO:
Only if intBoard > -1
Set intManDir = 3 (right)
Set intManPos = 115 (bottom center)
Set the man timer enabled to True
Code "tmrMan":
Use "Select Case intManDir" to move the man:
"Case 0:"
if the man is not yet at the top of the game board then
if the next small square is NOT visible then
decrease the top of the man by the height of one small square
subtract 11 from "intManPos"
change the man picture to the correct intManNum up
"Case 1:"
if the man is not yet at the bottom of the game board then
if the next small square is NOT visible then
increase the top of the man by the height of one small square
add 11 to "intManPos"
change the man picture to the correct intManNum down
"Case 2:"
if the man is not yet at the left side of the game board then
if the next small square is NOT visible then
decrease the left of the man by the width of one small square
subtract 1 from "intManPos"
change the man picture to the correct intManNum left
"Case 3:"
if the man is not yet at the right side of the game board then
if the next small square is NOT visible then
increase the left of the man by the width of one small square
add 1 to "intManPos"
change the man picture to the correct intManNum right
Copy all the "3" pictures and paste them as "1" pictures -- this will make the man open and close his mouth more evenly
Use "Select Case intManNum" to change the mouth number:
"Case 1: intManNum = 2"
"Case 2: intManNum = 3"
"Case 3: intManNum = 4"
"Case 4: intManNum = 1"
Gimick -- How can you make the man's mouth move even when the man is not moving?
When a score event occurs, add to or subtract from the existing score
Score events in Pac Man include: eating a visible food, eating a blue ghost, being eaten by a red ghost
Lab Assignment -
Modify the Visual Basic program "vbPacMan" to keep track of man lives and score:
To keep track of how many food pellets are visible, count them when you draw them
To keep track of how many food pellets are eaten, count them when TheMan runs over them and they're visible
To eat the food pellets when TheMan goes over them, if they're visible make them invisible
If pellets visible equals pellets eaten then Pac Man wins
Display all numbers on labels on the form
New variable: intManLives and set to 3 in Form_Load()
If any ghost every laps TheMan (top & left equal) then display a message and decrease intManLives
To change ghost eyes (pix 1 or pix 2) new variable: intGhostEyes(3) and set to 1 in Form_Load() when loading ghosts
At bottom of tmrGhost change picture -- if intGhostEyes(intGhost) = 1 display pix 1 and intGhostEyes(intGhost) = 2 if intGhostEyes(intGhost) = 2 display pix2 and intGhostEyes(intGhost) = 1
To change TheMan (make his mouth move) new variable: intManNum where 1=normal, 2=narrow,3=normal, 4=wide
Test intManNum at bottom of tmrMan and display proper picture and change intManNum
Continue working on your Microsoft PowerPoint presentation
Create a Microsoft Access database "petStore"
Create the database "perStore" in your VB folder
The following may be considered a "data dictionary" describing the tables in the database and the fields in each table and the field data type and what the fields do
Create a table "employee" with fields for:
employeeID - autoNumber - key
firstName - text - employee first name
lastName - text - employee last name
startDate - date - employee hire date
salary - currency - employee hourly wage
Create a table "customer" with fields for:
customerID - autoNumber - key
firstName - text - customer first name
lastName - text - customer last name
street - text - customer street address
city - text - customer city address
state - text - customer state address
zip - text - customer zip code address
Create a table "inventory" with fields for:
partNumber - autoNumber - key
partName - text - name and description of part
cost - currency - purchase price
price - currency - sales price
quantity - number - quantity on hand
Create a table "salesHeader" with fields for:
salesNumber - autoNumber - key
salesDate - date - date of sale
employeeID - number - will link to employeeID in employee
customerID - number - will link to customerID in customer
Create a table "salesDetail" with fields for:
salesDetailNumber - autoNumber - key
salesNumber - number - will link to salesNumber in salesHeader
partNumber - number - will link to partNumber in inventory
quantity - number - quantity sold
Create relationships:
employeeID in employee to employeeID in salesHeader
customerID in customer to customerID in salesHeader
salesNumber in salesHeader to salesNumber in salesDetail
partNumber in inventory to partNumber in salesDetail
Create lookups in design view:
lookup employeeID in employee for employeeID in salesHeader
lookup customerID in customer for customerID in salesHeader
lookup salesNumber in salesHeader for salesNumber in salesDetail
lookup partNumber in inventory for partNumber in salesDetail
Career - The Cover Letter, cont'd, a tutorial from quintCareers.com
SQL is a standard computer language for accessing and manipulating databases. Here is a tutorial from w3schools.com:
Home - learn how to use SQL to access and manipulate data in database systems
Intro - a standard computer language for accessing and manipulating databases
AND OR - used in a SELECT WHERE clause to join two or more conditions. The AND operator displays a row if ALL conditions listed are true. The OR operator displays a row if ANY of the conditions listed are true
IN - used in a SELECT WHERE clause if you know the exact value you want to return for at least one of the columns
BETWEEN AND - used in a SELECT WHERE clause to select a range of data between two values which may be numbers, text, or dates
Alias - used to rename column names and table names
JOIN - used in a SELECT WHERE clause to select data from two or more tables
Summary - execute queries, retrieve data, insert new records, delete records and update records in a database with SQL
Modify a Visual Basic program "vbPetStore.vbp" to insert, update, and delete records from the "petStore" Microsoft Access database:
Add, using a new form with all fields except "customerID":
I can't think of a way to use the existing form, so I'll use another
Add a Command Button Object named "cmdAdd" onto form "frmCustomers"
datCustomers.RecordSource = "" ' close the record
datCustomers.DatabaseName = "" ' close the database
frmAddCustomers.Show ' show the Add Customers form
frmCustomers.Hide ' hide the Customers form
datCustomers.DatabaseName = "petStore97.mdb" ' open the database
datCustomers.RecordSource = "customers" ' open the record
Add a new blank form "frmAddCustomers"
Add labels and textboxes for all fields: fName, lName, street, city, state, zip
Add a Data Object "datCustomers" with DataBaseName "petStore97.mdb" and RecordSource "customers"
Add a Command Button Object and code to Close
frmCustomers.Show
Unload Me
Add a Command Button Object and code to Add
datCustomers.Recordset.AddNew ' create a new record in the table
datCustomers.Recordset!fName = txtFN.Text ' set the text for the first name field
datCustomers.Recordset!lName = txtLN.Text ' set the text for the last name field
datCustomers.Recordset!street = txtS.Text ' set the text for the street field
datCustomers.Recordset!city = txtC.Text ' set the text for the city field
datCustomers.Recordset!state = txtST.Text ' set the text for the state field
datCustomers.Recordset!zip = txtZ.Text ' set the text for the zip field
datCustomers.Recordset.Update ' update the new record, completing the add new record
datCustomers.Recordset.MoveFirst ' move to the first record
txtFN.Text = "" ' clear the textboxes
txtLN.Text = ""
txtS.Text = ""
txtC.Text = ""
txtST.Text = ""
txtZ.Text = ""
txtFN.SetFocus ' set the focus to the first textbox
Save & Test
Change, use the Data Control to locate the correct record then change the data in the Textboxes:
Use a Checkbox Object on the "frmCustomers" form to control whether the textboxes are enabled or disabled
Create a subroutine "enableAll()" to enable the textboxes and disable the data object
Create a subroutine "disableAll()" to disable the textboxes and enable the data object
Call "disableAll()" in the "Form_Load()"
Add a Checkbox Object "chkModify" with the caption "Modify Record"
Double-click it to create the subroutine "chkModify_Click()"
Test the value property and call "enableAll()" or "disableAll()"
Save & Test
Delete, use the Data Control to locate the correct record then delete the record:
QUIZ - Take the SQL Quiz 1. Click the link and follow the instructions. PRINT AND HAND IN. 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 or Access database 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 for help
QUIZ - Visual Basic Quiz database program "vbPetStore":
Modify your existing Visual Basic program "vbPetStore.vbp" to read the "petStore97.mdb" database "employees" table. Get as much done in the time you have available
Requirements:
Use "frmCustomers" and code for ideas and sources
Add a new form "frmEmployees"
Add an object and connect to the database and table
Add textboxes (disabled) to display all the fields in each record
Add the ability for the user to search
Add the ability for the user to insert
Add the ability for the user to update
Add the ability for the user to delete
Save & Test
Considerations:
Test in phases or steps -- don't try to write the entire program and then test at the end
Remember when you connect the database that Visual Basic 6 (1998) does not work with Access 2002 -- connect the correct database "petStore97.mdb"
Connect the correct table -- "employees"
For each object that will display field data, connect the source first then field
How will you control the user ability to search?
How will you control the user ability to insert new records?
How will you control the user ability to update existing records?
How will you control the user ability to delete old records?
DO THE EASY PARTS FIRST
Some of you will not finish
Do as much as you can -- I will grade your work as if it were complete
I will subtract points for time not spent working
Do the work on the "C:" drive in the "myDocuments" folder -- it's faster and more secure and less error prone than waiting for the network to find "H:"
Copy the folder with the project and form and any images to the correct "Q:" folder for me to assess
Grading:
Works with all requirements specified above (50 pts)
Has "Option Explicit", programmer name/date, correct object and variable naming conventions, and looks good (25 pts)
Has extra features remembered from programs written in the past (25 pts)
Work on your Microsoft PowerPoint presentation class advertisement project
Modify the Visual Basic game program "vbMatchGame":
Complete the subroutine to set the board - use a list of 0 - 15 numbers 0 - 7 & 0 - 7 to choose which picture will be loaded into which box. Randomly choose one of the 0 - 15 numbers and remember which box it is placed into:
Declare an array variable "intPicNum(15)" to remember which pictures are loaded into which squares
Load "intPicNum(15)" with the numbers 0 - 7 and 0 - 7
Use "intPlace" to show which Image Object you are loading the picture and which place in "intPicNum()" you are
Get a random number between intCount - 15
Load the picture referenced by "strPicName(intPicNum(intRand))"
Switch "intPicNum(intPlace)" and "intPicNum(intRand)" using a temporary variable "intTemp"
In "form_Load()" set "imgPic()" top, left, width, height and test with visible and invisible
Randomize!
Add an Image Object "imgCover" to cover the pictures, height & width = 2000, picture, stretch
Copy and paste a total of 16 (0 - 15) of these CREATE A CONTROL OBJECT
In "form_Load()" set "imgCover()" top, left, width, height and test with visible and invisible
Code the "New Game" menu option: "Call setBoard()"
Double-click on "imgCover" to create a subroutine "imgCover_Click()" and write hte code:
New variables: "intCountClick", "intClick1", "intClick2"
In "setBoard()" set "intCountClick = 0"
Create a Select Case to evaluate the value of "intCountClick"
"imgCover_Click()" will have one parameter variable: "Index"