carbonize.co.ukcarbonize.co.uk

Ultraedit
UPX
Y!Tunnel
Trillian
YahELite
Opera
Ad Aware
YahSEek


Valid HTML 4.01!

Valid CSS!

Advertisement
Visual Basic String Functions
Nearly all your VB projects will involve a string function at some point in it's creation.

Format
If you need to control the display features (such as number of decimal places) you use the Format function
This function has two arguments, the first is the string to format, the second is how to display the string.
As an example, to display NUMBERS with no more than two decimal points, use:
  NUMBERS = 2.4531983394
  txtDemo.Text = Format(Numbers, "#.##")
This would give us 2.45

Left
The Left function is used to extract a certain amount of characters from the left of the string. For example : -
  WebSite = "www.carbonize.co.uk"
  Leftstring = Left(WebSite, 5)

This makes Leftstring equal to "www.c"

Right
The Right works the same way as the Left function but extracts the characters from the right of the string. For example :-
  WebSite = "www.carbonize.co.uk"
  Rightstring = Right(WebSite, 7)

This makes Rightstring equal to "e.co.uk"

Mid
The Mid function is used to extract characters from anywhere in a string. You just define the starting point and the number of characters to extract. For example :-
  WebSite = "www.carbonize.co.uk"
  MidString = Mid(WebSite, 5, 9)

This makes Midstring equal to "carbonize"

Len
The Len function is used for determining the length of a string. For example :-
  WebSite = "www.carbonize.co.uk"
  LenString = Len(WebSite)

This make LenString have a value of 19

Instr
The Instr function is to locate a substring within a string. It uses 3 arguments to achieve this. Argument 1 is the point in the string to start looking from, Argument 2 is the name of the string to look through, and Argument 3 is the substring to locate. For example :-
  WebSite = "www.carbonize.co.uk"
  Location = Instr(4, WebSite, "oni")

This will look through the string 'WebSite', starting at character 4, for the substring "oni". If the substring is located the program will return the value which is the position of the first character of the substring, so in our example Location would equal 9, which is the position of the "o" in "oni".

Next we look at a pair of very useful functions, Asc and Chr.
Every ´typeable´ character has a numeric representation called an ASCII ("askey") code. The Asc function returns the ASCII code for an individual character. For example :-
  Asc("A")
Will give you the ASCII code for "A" which is "65"
The Chr function works the other way around. Chr will return character respresented by an ASCII code. For example :-
  Chr(75)
This returns the character represented by the ASCII code "75", Which is "K".

Lcase
This is a very useful command to know. The Lcase command will convert all the letters in a string to lowercase (eg. 'Carbonize SUCKS!!' becomes 'carbonize sucks!!')
The format for using this command is Lcase(string)


Back to top | Contact me