In this part of the video series you’ll learn the following:
Working with variables.
String expressions
String Concatenation
Inputbox examples
Currency Formatting
Step through code
Debug code
Immediate window samples
if statement example
one line if statement example
if else statement example
if elseif statement example
select case statement example
Click here for more VBA Debugging help
Now, before you take the quiz, I want to make sure you are informed of some particular topics:
Sub TestTheFX() Dim strName As String strName = GetFName MsgBox strName End Sub Function GetFName() 'this sets the return value of the function GetFName= "Mortimer" End Function
Passing Parameters To Functions
Passing a Parameter to a function is like handing off a football to another runner, or passing the baton to someone else, or like putting a big block of meat in a meat processor, and out comes hamburger .
The parameter being passed is called an argument. The arguments get processed by the function.
Like any people who argue with each other, the argument is the subject of the conversation. The reason why people argue is regarding some subject which pleases or displeases them.
(Ok, fine, I’ll stop with the metaphors 🙂 ).
It will give the function the parameter is passed to, something to work with.
In the following code, we are passing the car’s number to the function to find out what color it is. With its current parameters, we’ll get “Purple” for the car’s color:
Sub ShowCarColor() Dim intColor As Integer Dim strColor As String intColor = 4 strColor = GetColor(intColor) MsgBox "The color of car #" & intColor & " is " & strColor End Sub Function GetColor(intThisCar As Integer) As String Select Case intThisCar Case 1 GetColor = "Blue" Case 2 GetColor = "Red" Case 3 GetColor = "Green" Case 4 GetColor = "Purple" Case 5 GetColor = "Yellow" Case Else GetColor = "Unknown" End Select End Function
Variable Scope
An argument basically can be passed “under the radar” because you are either passing it within the same form module, or to some other basic module which is used by many forms.
You can learn more about a variable’s scope, but viewing my other post. (Click here)
Procedure Scope
Procedures are private in scope within a form’s context. As I stated previously basic modules can be used by multiple forms.
Again, click here to learn more about a variable and procedure’s scope. Click here
Basic modules have a public scope by default, and if you don’t declare the procedure or function as Public Sub or Private Sub, it will be Public by default.
Check for understanding – Video 4
<< Free Access programming tutorial Video 3
Free Access Programming tutorial Video 5>>






