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

using formatstr

Status
Not open for further replies.

prgm

Programmer
Apr 28, 2005
6
US
I have a big prolem here.... i have created a vb appln. in which it reads and write to a texr file users iformation. I have used "|" to separate the records and ";" to show difference between column

i have content like

tom;03/09/2004;john|david;02/01/1999;elizabeth and so on.......

these are displayed int he list box as

tom;03/09/2004;john
david;02/01/1999;elizabeth

but i wnat them to be displayed as

Name birthDate Parent's Name
------------------------------------------------
tom 03/09/2004 john
david 02/01/1999 elizabeth
and so on.....

i want them in the listbox...i dont know..how do i bring them to this format..can any one suggest plz.

I could have split them wiht ; and repalce them with soem spaces but..i need exact formatting..in soem cases...if the name length is too small then the b'date would come near..i was suggeted to use formatstr() function but i dotn know how it works...for my pgm.






 
PRGM,
It sounds like...
When you read from the text file, you will have to search for the "|" and recover numerous strings that each consist of 1 record (name;birthdate;parent).
Then you will have to search for the occurrences of ";" and split each record string into its components.
Then you will have to set each component into an array of 3 columns.
Then you can put the array into a 3 column list box.
Putting headers into a list box is a topic that has been discussed elswhere. I have not seen a good answer yet. There may not be a way to get column heads into a list box without the data being on a worksheet.

I expect you'll have blister on your fingers.

Greg
 
Use the Split function to get them into an array, then loop through the array adding a vbTab character after each array item.
Code:
Private Sub Command1_Click()
Dim strA as String
Dim lngCount as Long
Dim lngCount2 As Long
Dim aryB() As String
Dim aryC() As String
Dim temp as String
strA = "tom;03/09/2004;john|david;02/01/1999;elizabeth"
aryB = Split(strA, "|")
For lngCount = LBound(aryB) To UBound(aryB)
aryC = Split(aryB(lngCount), ";")
temp = ""
For lngCount2 = LBound(aryC) To UBound(aryC)
temp = temp & aryC(lngCount2) & vbTab & vbTab
Next lngCount2
List1.AddItem temp
Next lngCount
End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
hi ,

gwf : I don't know how to to set each component into an array of 3 columns.

Can you help me with this.
johnwm:Thanks for the code but stince we use a tab here...sometimes if the name is of length >7 then the date's format becomes disturbed.


HERE IS MY CODE I have also

Dim sText() As String
Dim nFileNum As Integer
Dim rep As Integer
Dim sNextLine As String
Dim lLineCount As Integer
Dim lngCount As Long

Form1.Cls
' Get a free file number
nFileNum = FreeFile()

' Open Test.txt for input. App.Path returns the path your app is saved in
Open App.Path & "\Test.txt" For Input As FreeFile

sNextLine = Input(LOF(nFileNum), #nFileNum)
Close #(nFileNum)

sText = Split(sNextLine, "|")

For lngCount = LBound(sText) To UBound(sText)
mySplit = Split(sText(lngCount), ";")
temp = ""

For lngCount2 = LBound(mySplit) To UBound(mySplit)
temp = temp & mySplit(lngCount2) & vbTab & vbTab
Next lngCount2
List1.AddItem temp
Next lngCount
End Sub
 
Have a look at the List property of the UserForm.ListBox object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top