Hi Guys:
i thought I'd mention CamelCasing as a technique for naming objects and
variables.
CamelCasing just means capitalizing the first letter of any word in a object
name but, in this version of CamelCasing, leaving the first few letters lower
case.
This is because the first few letters will tell us what type of object the
object is.
These letters are just something we make up - there are no enforced
standardization rules.
Note that by capitalizing the first letter of each word in an object name that
the variable name will read much better with WindowEyes as well.
Let's take a look at a few...
Say we want a couple string variables that will hold the FirstName and the
LastName of a person.
We call them "FirstName" and "LastName". Not confusing but,
in Camel Casing they might be called "strFirstName and strLastName.
Note the str prefix. This tells me that these are string variables whenever I
see them anyplace in my code.
Now let's take a look at a EditBox object to gather or display the FirstName
and LastName of a person.
They might be called "FirstName" and LastName.
See how they could be questioned in a long project. If you just hear FirstName
is that the FirstName string variable or the FirstName EditBox?
OK, try this:
ebFirstName and ebLastName.
Now you see the "eb" prefix and know they are EditBoxes and not the string
variables.
I usually use the "tb" prefix since we call EditBoxes TextBoxes in Vb.net but
since I see them referred to as EditBoxes in VBScript I used "eb" as the
prefix.
Remember you just make up whatever prefixes you like but try and be consistent
so you quickly memorize the ones you most often use.
Here are a few I can think of off the top of my head I often use:
ebFirstName, FirstName EditBox.
lbFirstNames, A ListBox named FirstNames.
lvFirstNames, A ListView calledFirstNames.
diagFirstName, A DialogBox called FirstName.
aryFirstNames an array called FirstNames.
intFirstName, A integer Variable called FirstName.
decFirstName, A Decimal Variable called FirstName.
And so on...
For any type of object you use you can invent a short abbreviation for that
object type and just append it to the front of the object name to clarify what
type of object it is.
Now, in tonights class offered by Chip we will go over the Dictionary object.
Let's look at using it with CamelCasing...
Note that the following is code off the top of my head so might not be exactly
syntactically correct but it should be quite close.
First we define our dictionary.
You can check it out after the class if you want to verify, or refute it's
validity.
Dim dicStudentGrades
Set DicStudentGrades = CreateObject( "Scripting.Dictionary" )
dicStudentGrades.Add "Bob Smith", "A"
dicStudentGrades.Add "Sally Smuthers", "C"
dicStudentGrades.Add "Rick Sandworker", "B"
Now Our dictionary holds 3 students with the student name as the "Key" and
their Grade as the "Item".
Let's iterate the dictionary displaying the Student Names and their Scores.
We can't directly iterate over the dictionary so we extract an array holding
all the keys in the dictionary.
This will be an array of StudentNames from the Dictionary Key object.
aryStudentNames = dicStudentGrades.Keys
Now we define a variant object to represent one student name in our array
search.
Dim varStudentName
Now we iterate the array of student names and use each key, student name, to
pull the grade for that student to display in the message box.
For Each varStudentName in aryStudentGrades
MsgBox varStudentName.ToString() & " Grade Is " & dicStudentGrades.Item(
varStudentName )
Next varStudentName
Here, even though we had to jump through the hoops of creating an array to
temporarly hold the StudentNames, the process is pretty clear since we used the
object type of each object as a prefix to the actual CamelCased object names.
If, a year or so later, you had to revisit this code it would be clear as to
what exactly was going on.
If we had used x, y and z the logic would be clouded and require some research
to figure out.
That is, unless you are blessed with total recall, something this old fat blind
guy doesn't seem to have - grin.
Again, if you load up this example, check it for syntax errors since this is a
demonstration of using CamelCasing and not a Scripting, Dictionary, technicals
lesson...
Well That's about all for this topic.
See you all tonight at 7 and...
Happy Programming!
Rick USA