Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how i put a given no. of blank spaces after a word 1

Status
Not open for further replies.

goilaswati

Programmer
Mar 3, 2003
20
0
0
IN
sir
i want to print a no. of blank spaces after a word
and then again a word
sir i take a text box
and the value of this text box(which is a string) i take
into a string type variable a like
a=len(text1.text)
then
another string type variable b
b=12-a
because i want b no. of spaces after a
if i print a & b then it will display
string a then value of b(like 10 or 8)
but i want b no. of spaces after a then again any word.
then plz tell me the correct syntax.
swati
 
Hi goilaswati,

if you use a=len(text1.text) then a will hold the number of characters in text1! and b = 12 - a will again be a number! May be you could be more precise or even paste your code here.

just as an indicator, if a was a string and b an integer then:

option explicit

public sub addBlankSpaces()
Dim a as String
Dim b as Integer
Dim i as Integer

a = myString
b = 5

for i = 0 to b
a = a & " "
next

end sub

after this routine has completed you will have:

a = "myString "

 
VB has two functions that let you do this as well. (code is in blue)

1) Space function: Return a string of spaces equal to the number it is passed.
sResult = "myString" & Space(10)

2) String function: Return a string of a defined character equal to the number it is passed.
sResult = "myString" & String(10, " ")

Example of find and replace. This will the "," with multiple spaces

sText = "me;myself;I"
sSpaces = Space(3)
sResult = Replace(sText,";",sSpaces)

sResult should now be "me myself I"
 
Here's an alternative solution, just for the heck of it:

Private Function SpacePad(strText As String, PadCount As Long) As String
SpacePad = Space(PadCount)
LSet SpacePad = strText
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top