January 19, 2021
Hot Topics:

No Strings Attached

  • By Sam Huggill
  • Send Email »
  • More Articles »

"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 shuggill@domain.softnet.co.uk

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date