VBA Programming 101: Lecture 01
Before I begin Excel or VBA there are three terms you need to be very comfortable with: Strings, variables, and functions. So without further ado,
STRING: A string is more than one character in a row. Example of strings: 18463 ADJOGKN FEH355#%^
Q) How does a computer program know that what you are entering is a STRING and not some other data type (such as a function or variable)? A) Almost all programming languages require quotes around a string. This tells the program not to do any fancy shtick on it, just read it as just a jumble of characters.
So, if a program sees: **Hello **- it is going to try to figure out how to execute the program Hello. But if you put quotes around it: "Hello" the program will now know that this is just a dumb string you want it to accept. It will not attempt to do any fancy magic with it.
Variable: A variable is a character (usually a letter) that can change its meaning. The word variable comes from two words: VARY + ABLE, so it is able to change.
An example:
Let's say X is equal to 7. This statement is true: "There are X days in a week".
Now if we change X and say X = 9, the statement "There are X days in a week" is FALSE. Same statement, but what you reassign the variable to a different meaning, it means something entirely different.
**Function: **A machine that accepts an input, does some predetermined procedure to the input value, and returns the new value.
An example:
Let's call our function Bob. Function Bob takes anything that is put into it and DOUBLES IT. So what would happen if we put $3 into Bob? Let's find out!
Bob($3) = $6
"( )" is where you place the input usually, and after the "=" is where your output value will come. Let's look at another:
Bob("Cat") = "Cat Cat"
So here we put in a string and Bob doubled our input as expected.
Thanks for tuning in guys, and please vote this thread up if you enjoyed this read. It takes quite a bit of time to put together but if I see people are enjoying them I will continue posting these lectures.
FarRock