by Dinesh Thakur Category: Lists Loops and Printing

VB provides string functions such as Left ,Right ,len.


Syntax is as follows:


Left(String Expression, no. of characters)

Right(String Expression, no. of characters)


String expression in Left and Right statements may be a string variable, string literal or text properties. Number of characters and start position are both numeric and may be variables, literals or numeric expressions.


Ex. Left(txtName.text,5)

„Returns first 5 characters


„Returns last one character

Len(String Expression)


We can use the len function to determine the length of string expression. We may need to know how many characters the user has entered or how long list element is. The value returned by the len function is an integer count of the number of characters in the string.

Ex. Len(“Visual Basic”)

„Returns no. of character as 12


„Returns no. of character in the textbox

If len(txtNames.text)=0 then

Msgbox “Enter a Name”,VBInformation,”DataMissing”

End IF


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.