TheSwamp

Code Red => VB(A) => Topic started by: Guest on September 04, 2007, 09:18:00 AM

Title: Save Multi-Column Listbox to Text File
Post by: Guest on September 04, 2007, 09:18:00 AM
I've got a multicolumn listbox that has block names and counts.  I want to save the info to a TXT file but maintain the columns.  I know how to save to a TXT file, but I don't know how to maintain those columns.  Tabs won't work because some block names are longer than others and by using a tab for spacing, it may end up kicking a block count out of alignment.

Ideally what I'd like to do is have a set string length for the block names (it would need to include spaces to make up the difference of the other shorter/longer block names) and then have a set length for the block count.

I hope this is making sense.


Right now, if I save the block count info to a TXT file, it would look something like this...

Quote
EXISTING DATA/VOICE OUTLET  2
EXISTING VOICE OUTLET   4
NEW AUDIO/VIDEO OUTLET  2
NEW DATA OUTLET 2
NEW DATA/VOICE OUTLET   3
NEW VOICE OUTLET    2


But I want it to look like this....

Quote
EXISTING DATA/VOICE OUTLET2
EXISTING VOICE OUTLET4
NEW AUDIO/VIDEO OUTLET2
NEW DATA OUTLET2
NEW DATA/VOICE OUTLET3
NEW VOICE OUTLET2
Title: Re: Save Multi-Column Listbox to Text File
Post by: Keith™ on September 04, 2007, 09:39:35 AM
Unless you are using a fixed width font the text won't exactly line up anyway, but you can get it close ....

Try this to expand the length of the description to a desired length:
Code: [Select]
Public Function ExpandText (ByVal strSource As String, ByVal intLength As Integer) As String
While Len(strSource) < intLength
 strSource = strSource & " "
Wend
ExpandText = strSource
End Function

Then append the count to the end
Title: Re: Save Multi-Column Listbox to Text File
Post by: Guest on September 04, 2007, 09:46:39 AM
That's perfect!  Thanks, Keith.
Title: Re: Save Multi-Column Listbox to Text File
Post by: Keith™ on September 04, 2007, 09:56:18 AM
You are welcome ...
Title: Re: Save Multi-Column Listbox to Text File
Post by: Guest on September 04, 2007, 02:33:26 PM
So I made a slight change to the function below - substituted the space with a period and now my output looks like below.


Quote
Public Function ExpandText (ByVal strSource As String, ByVal intLength As Integer) As String
   While Len(strSource) < intLength
      strSource = strSource & "."
   Wend
   ExpandText = strSource
End Function


TXT file output.
Quote
Device Name                   #
=====================================
EXISTING DATA OUTLET...................................3
EXISTING DATA/VOICE OUTLET.........................3
EXISTING VOICE OUTLET.................................3
EXISTING WAP...............................................1
NEW DATA OUTLET.........................................6
NEW WAP......................................................2
NEW WAP (WALL-MOUNTED).............................4

Thanks again, Keith!
Title: Re: Save Multi-Column Listbox to Text File
Post by: Keith™ on September 04, 2007, 03:02:45 PM
Glad it worked for you .. now if I could get someone to help me figure out how to dynamically create a bitmap in memory that can be put into a ImageList, I would be all set