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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding leading spaces to a string...

Status
Not open for further replies.

SPRobson

Programmer
Jul 5, 2001
18
0
0
EU
Hi

I am trying to sort numerical columns of a listview control. I've worked out that I must add leading spaces to my number strings to do this. For example, if I have the following numbers 10.234, 100.234, 1000.234 then I must convert each string to " 10.234", " 100.234", "1000.234". How do I do this? Is there something in the Format function I can use?

Many thanks

Simon Thanks

Simon
 
In the module create a user type field.

type SetString 'any variable name
strNumber as string * 6 'the number can be as long or
'or short as needed
end type

When sending the number to the string, use:

RSet strNumber = str(10.00) ' the number 10.00 is
' representing a number or
' variable. The RSet aligns the
' number to the right.
 
Hi

Thanks alot. I thought there must be a VB function somewhere to help me.

Thanks again,

Simon Thanks

Simon
 
There are a variety of ways of doing this, but to give you a solution along the lines you are thinking:

1. You need to establish the length of your longest numeric string or arbitarily choose a length that you know is going to be longer than your longest numeric string (I'm not a fan of this latter option; it means that you are hard-coding in limitations)
2. Then you can use Format as followsomething like this:
[tt]
NewNumberString = Format(OldNumberString, String(LengthOfLongestString,"@"))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top