In this part of the video series you’ll be able to answer the following questions:
1. What answer will be generated by the following code?
2. What will the ending value of strResponse be?
3 & 4. What value will appear in the message box generated by the following code?
Option Compare Database Option Explicit Sub FinishOrder() Dim dteOrder As Date dteOrder = InputBox("Enter Date") ShipOrder (dteOrder) End Sub Sub ShipOrder(dteShip As Date) dteShip = dteShip + 30 MsgBox "Ship Date: " & dteShip End Sub Sub Evaluate1() Dim intX As Integer Dim intY As Integer intX = 8 intY = 5 intX = intX + intY If intX = 8 Then MsgBox intX Else MsgBox intY End If End Sub Sub Evaluate2() Dim intCode As Integer Dim strResponse As String Dim strTemp As String intCode = 23 Select Case intCode Case 15 strTemp = "Orchid" Case 20 strTemp = "Morocco" Case 23 strTemp = "Cheese" Case Else strTemp = "Orion" End Select strResponse = "Code Name: " & strTemp End Sub Sub Evaluate3() Dim dblX As Double Dim dblY As Double dblX = 1.5 dblY = 2 * dblX If dblX > 2 Then MsgBox dblX ElseIf dblY > 3 Then MsgBox dblY Else MsgBox "Else" End If End Sub Sub Evaluate4() Dim blnOkay As Boolean Dim curPrice As Currency blnOkay = True curPrice = 5 If blnOkay Then MsgBox blnOkay ElseIf curPrice = 5 Then MsgBox curPrice Else MsgBox "Neither" End If End Sub
“And now a few tips before your quiz”:
The 3 Step Club
Step Into (F8)
When you use the Step Into function, your code is run line be line. If a line of code calls another procedure, the execution shifts to the called procedure, where you can continue to step into code, line by line.
Step Over
The Step Over function is similar to the Step Into function because it runs the next executable line of code. When Step Over is called, however, entire procedures will run without shifting your view of the code to the called procedure like the Step Into function does. Step Over treats the called procedure like one step.
Basically the Step Over function runs a procedure without stepping into it.
Step Out
The Step Out function will run all the called procedures in one step, similar to the execution of the Step Over function. Using the The Step Out function, however, runs all the nested code in one step, but the cursor is returned to the next executable line of code in the calling procedure.
The Immediate and Watch Windows
Personally, I use the Immediate window a lot to check the current value of a variable. You can press CTRL+G on your keyboard when you are in the VBA Editor to launch the Immediate window, and then check out a variable’s value by typing something like:
?{variablename}
or
?strVariable
Here’s an example:
I have also used the Watch window to check out the value of a variable as it’s passing through various procedures.
You can launch the Watch window by doing this:
If you need to figure out why a variable gets a certain value at a certain point in your code, set the Watch up like this:
This will tell your code to “Break” at a certain point so you can “Step Through (F8) (yes you are already in the procedure, now you just need to step through)” the procedure to see why a certain value is given.
Navigating The Code Window
Sometimes you’re unclear about how a certain variable gets its value and you need to go to a function or sub procedure that is in another module. This can be cumbersome and time consuming to try and find the function or procedure.
For an easier way, use the keyboard combination {SHIFT + F2} or the mouse shortcut “Definition”
Here’s an example of the SHIFT + F2 keyboard combination:
Here’s an example of the “Definition” shortcut:
These examples use an API function declared in the same module, but you can still use this from module to module.
Make sure you check out http://vbahowto.com/vba-debug-part-1/ for more debug information.
<< Free Access programming tutorial Video 4
Free Access Programming tutorial Video 6>>
Check for understanding – Video 5






