Wyo VB Lecture Notes
Objective #1: Use String variables.
strName = "John Doe"
This assigns the string value "John Doe" to the variable strName.
strNameA = "John"
strNameB = "John "
strLastName = "Doe"
strExample1 = strNameA + strLastName
strExample2 = strNameB + strLastName
strExample1 is currently equal to "JohnDoe" and strExample2 is "John Doe" because of the included blank space in strNameB.
Here are more examples involving string concatenation:"computer" + "programming" becomes "computerprogramming"
(VB does NOT automatically embed a space between the words)
"Wyomissing " + "Area" displays as "Wyomissing Area"
(notice the space after the 'g' in "Wyomissing")
"54" + "32" displays as "5432"
(both operands are strings and NOT numeric values)
"54" + 32 displays as 86
(when at least one of the two operands is a number, the + symbol adds rather than concatenates)
54 + 32 displays as 86
(both operands are numeric values so mathematical addition occurs rather than concatenation)
You can also use the += operator to concatenate two strings as in
strName = "John"
strLastName = "Doe"
strName += strLastName
strName is now "JohnDoe" (with no space in between)This last statement is equivalent to
strName = strName + strLastName
("A" < "B") simplifies
to True since the Unicode value of A is 65 and the
Unicode value of B is 66.
("D" < "d") simplifies
to True since the Unicode value of uppercase D
is 68 and the Unicode value of d is 100.
("Apple" < "Banana") simplifies
to True since the Unicode value of A is 65 and
the Unicode value of B is 66.
("ABC" = ("A" & "BC")) simplifies to True since the "ABC" is equal to "ABC" after
the string concatenation.
("Apple" < "Aphrodite") simplifies
to False since the Unicode value of the second p in Apple is 112
and the Unicode value of h is 104.
("Zeus" < "aphrodite") simplifies
to True since the Unicode value of uppercase Z is 90 and the Unicode
value of lowercase a is 97.
Another Example:
strMyName = "Minich"
strYourName = "Anderson"
If (strMyName > strYourName) Then
MessageBox.Show("Ha Ha, I am greater than you alphabetically")
End If
strName = "FrEd"
MessageBox.Show(strName.ToUpper()) "FRED" will show up in the message box
MessageBox.Show(strName.ToLower()) "fred" will show up in the message box
Trim(" Fred") = "Fred"
Trim(" Fred ") = "Fred"
Trim("Fred") = "Fred"