V-5 Using Variables and Arrays
![Rectangular Callout: In my opinion, this is one of the most important subjects on VBN [variables and arrays] Dave Bohm](UsingVariablesandArrays_files/image001.gif)









Starting Visual Studio.NET



Instructor Garth Schulte pre-set this interface up, but didn’t put any code behind it – yet.
![Rounded Rectangular Callout: He opened the Properties window by ViewàProperties Window [F4] key](UsingVariablesandArrays_files/image020.gif)























![Rectangular Callout: Now the variable FirstName is both declared and typed. I like to use the word typecast to avoid confusion since that’s really what is meant here. [We don’t mean typed as in typewritten.]](UsingVariablesandArrays_files/image055.gif)























![Rounded Rectangular Callout: Remember that the statement:
Dim strFirstName As String
COULD HAVE been written as merely:
Dim FirstName
And it still would’ve correctly declared the FirstName variable. [Same for the other variables.]
However Dim strFirstName As String
is the far better way to do it. Who can tell me the 2 reasons why? [Test Question]](UsingVariablesandArrays_files/image088.gif)

Dim strFirstName As String
COULD HAVE been written as
merely:
Dim FirstName
And it still would’ve
correctly declared the FirstName variable. [Same for the other variables.]
However Dim strFirstName As String
is the far better way to do
it.
Answer 1 in Dim strFirstName As String
The “str” prefix makes it easier for people reading
the code to see that it’s a string variable.
Answer 2 in Dim strFirstName As String
The As String correctly type-casts [or types] the variable as a string
variable. This makes it easier for VB.NET reading the code to see that it’s a
string variable.
If the variable
is not typed [type-cast] what will VBN see this variable as?
What type of
variable? [Test Question]
Why is this not
good? [Test Question]
Answers:
If the variable
is not typed [type-cast] what will VBN see this variable as?
What type of
variable? [Test Question]
An Object type variable.
Why is this not
good? [Test Question]
An Object type variable uses
a lot more memory space than a string type variable. The program will run
slower.




![Rectangular Callout: These lines of code display the values in the Labels that the user typed into the Text Box
[note replay video section 23:23 to 24:17.]](UsingVariablesandArrays_files/image092.gif)

![Rectangular Callout: Intro to Arrays, which are simply Variables with more than one element which are the same data type.
E.G. all string or all integer, can’t mix and match data types. [Test Question]](UsingVariablesandArrays_files/image095.gif)
![Rounded Rectangular Callout: The reason he used (7) when he needed 8 elements is because arrays are _____” index based”, [Test Question]](UsingVariablesandArrays_files/image096.gif)




















![Rectangular Callout: Here Garth placed values [the names of Trainers] into the elements of the array.](UsingVariablesandArrays_files/image125.gif)





![Rounded Rectangular Callout: It basically says that if Radio Button 1 [radbtn1] is checked…](UsingVariablesandArrays_files/image133.gif)




























![]()


![Rectangular Callout: The (4, 1) just means that there are still only 4 name fields, but a 2nd dimension [the 1) ].](UsingVariablesandArrays_files/image175.gif)





