Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 20th, 2006, 3:27 AM   #1
pastalover
Newbie
 
Join Date: May 2006
Posts: 11
Rep Power: 0 pastalover is on a distinguished road
convert unarrenged .txt data to arrange .txt data

hi..

currently i'm taking over my friend job to gather all the employee data (almost 36000 data) of our company.i was given a .txt file which is not organized like below:

Albert ferrer,00000000003,albert@tm.com.my
Lee Hock Lye,00000000021,hllee@tm.com.my
Carlos Miera,00000000045,carlosm@tm.com.my


as a final result i should arrange these data as below:

Albert ferrerzzzzzzzzz|00000000003|albert@tm.com.my
Lee Hock Lyezzzzzzzz|00000000021|hllee@tm.com.my
Carlos Mierazzzzzzzzz|00000000045|carlosm@tm.com.my

my friend suggest that i should do a program which need to assgined the 3 spaces for name,employee no. and email..meaning thta i have to set the string so that the data is well arrenged..for example in name portion has 60 lenght,employee no has 11 length and email has 50 length so that all the data can be arranged parellelly..anybody can help?

(assume that "z" white font is space length)
pastalover is offline   Reply With Quote
Old Jun 23rd, 2006, 5:16 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 335
Rep Power: 4 mackenga is on a distinguished road
If I read you right, you want to pad out the fields so that they line up nicely. I'm not going to spend ages and do this for you - partly because part of me suspects this is an assignment rather than employee data for your friend's company, and partly because I have other questions to answer and hell, maybe even other things I'd like to do with my time!

Anyway, if you're using VB you might want to start by throwing a few controls on a form to kick this off; say a field where your user can enter the input filename and output filename. If you don't foresee doing this again ever, you can be pretty rough about this or even just hard code the values instead.

When your program actually goes to read the file, it will want to access the filesystem. The old school method would be a bit like this:

Open "inputfile.txt" For Input As 1
Open "outputfile.txt" FOR Output As 2

Then you could process the file with:

Line Input #1, strLine
' ... do some processing to sort out the alignment here
Print #2, strLine

This would be in a While loop looking to exit on Eof(1). The modern way to do it uses the Scripting.FileSystemObject - I suggest you google for this. It's quite straightforward to use really, especially for such a simple job.

Next, what do you actually do to process the file? First, look into the Split function and the For Each loop, as these will come in handy for breaking up the text. Then all you need is to output the fields and pad the names with spaces. You don't need to pad the numbers by the looks of it, or if you do it's by a constant number of spaces which is dead easy.

To output the right number of spaces, use a loop like:

...output the name, WITHOUT TAKING A NEW LINE...
For I = 1 To 50 - Len(strName)
    ...output a space...again, don't take a new line...
Next

Then you can output the number, any padding for that field and then the email address after which you can take a new line.

I hope these hints help you along, but I would advise against trying to trick people here into doing your homework. The denizens of this board are not as dumb as you imply that you think they are. 36000 employee records...that consist of a name, number and email address...in a CSV file!?

If this is for real and you're really working for a company, they have BIG problems and need to hire some software engineers.
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Old Jun 23rd, 2006, 5:22 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Why don't you see your own (identical) thread in the C forum? Sure, it's a different language, but the same comments and methods apply.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC