No Strings Attached

Tuesday Nov 19th 2002 by Sam Huggill

How long is a piece of string? In this article article you will learn to how to find the answer in Visual Basic.

"How long is a piece of string?" Is one of many well known sayings. In this article you will find out how to do that, and lots of other things.

String Conversion Functions

These four functions manipulate the ANSI codes and translate them into characters, or vice versa.

Asc() Chr$() Str$() Val()

Ansi String Conversion

Using the Asc() function, it will return the ANSI code for the first letter in the string, e.g.


Will return 65, which is the ANSI code for the letter "A".

Character Conversion

Using the Chr$() function, it will return the letter for the ANSI code given, e.g.

R$ = Chr$(65)

Will return the letter "A", which is the 65th character in the ANSI table. The value of the ANSI code must be between 0 and 255.

String Conversion

Using the Str$() function, it will convert the value to a string, e.g.

X = 4.1
S$ = Str$(X)
MsgBox S$

The message box will appear with 4.1 in it.

Value of string

Using the Val() function, it will return the value of the string up to the first non-numeric character, e.g.

R$ = "3.123E12"
X = Val(R$)

X will be 3.123000 It converts all the characters after the first non-numeric to 0. In this case, 3 characters were converted to 0.

String Concatenation

This simply means the joining of strings. Pretty simple yet very effective. E.g.

Fname = InputBox("Enter First Name")
Lname = InputBox("Enter Last Name")
YourName = Fname & " " & Lname
Print "Hello " & YourName

Further Discussion

If you would like to discuss any of the topics covered in this article in more detail, please email me at

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved