String Functions
String Functions
(Any function that returns a string can have a $ as a suffix on the function name, e.g. UCase$ or
Left$, etc.)
Asc(character) returns the ASCII code for the character (see Appendix B)
Function Results
UCase(“Hello”) HELLO
LCase(Prgname) visual basic
String(5, “A”) AAAAA
Len(Prgname) 12
Len(“hello”) 5
Left(“January”,3) Jan
Right(“January”,2) ry
18901888.doc
Left(Prgname,6) Visual
Right(Prgname,5) Basic
Mid(“January”,2,1) a
Mid(“January”,4,2) ua
Mid(Prgname,8,1) B
Mid(Prgname,8) Basic
Instr(1, “Have a nice day”, “nice”,0) 8
Instr(1, “Have a nice day”, “Nice”) 0
Instr(9, “This is an Instr function example”, “instr”) 0
Instr(9, “This is an Instr function example”, “instr”,1) 12
Asc(“B”) 66
Chr(33) !
Val(“0050”) 50
Val(“354.6AB5”) 354.6
Str(450.1) “450.1”
T he design and size for a sweatshirt for The Environmental Sweatshirts Company is based
on a product code. The first three characters of the code can be 100, 200, or 300 which
indicates the design. The last two characters indicate the size (XS, SM, etc.) This program
segment will take the product code typed into a textbox and display the design in an image and
the size in a label.
18901888.doc
A ll products at Consolidated Machinery have either the letter A or the letter C as the third
character in the product code. When the user enters the product code in the textbox
control and clicks the Verify control button, the application will display whether the
product code is valid or not.
C redit card companies use an algorithm to assign their account numbers. One algorithm is
to multiple every other digit of the next possible “account number” by 2. Then add all the
resulting numbers and us the last digit of the sum as the last digit of the account number.
For example, if the number 12345 was to be assigned to a new account…the algorithm would be
performed:
1 + 2*2 + 3 + 4*2 + 5 = 21 so the new account would be assigned the number 123451.
18901888.doc