October 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

No Strings Attached

  • November 19, 2002
  • 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.

R=Asc("ABCD")

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






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel