Wyo VB Lecture Notes
Objective #1: Use String variables.
name = "John Doe"
This assigns the string value "John Doe" to the variable name.
nameA = "John"
nameB = "John "
lastName = "Doe"
example1 = nameA + lastName
example2 = nameB + lastName
example1 is currently equal to "JohnDoe" and example2 is "John Doe" because of the included blank space in nameB.
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
name = "John"
lastName = "Doe"
name += lastName
name is now "JohnDoe" (with no space in between)This last statement is equivalent to
name = name + lastName
("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:
myName = "Minich"
yourName = "Anderson"
If (myName > yourName) Then
MessageBox.Show("Ha Ha, I am greater than you alphabetically")
End If
name = "FrEd"
MessageBox.Show(name.ToUpper()) "FRED" will show up in the message box
MessageBox.Show(name.ToLower()) "fred" will show up in the message box
Trim(" Fred") = "Fred"
Trim(" Fred ") = "Fred"
Trim("Fred") = "Fred"