×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

(OP)
Think that I hosed my profile after pretty much right after creation and posting my first question ever. Had two replies hit my mailbox but can't hyperlink back to find the Tek-Tips thread. I'm pretty out of my element data-formatting in VBS and am hoping for even a fairly representative example that is somewhat similar for me learn and apply the concepts. I see that guitarzan tried to assist, and possibly skip, too, but I couldn't hook back to the thread. Very sorry!

What I hope to accomplish through VBScript:

1. Read vertical text-based list and convert to horizontal comma-separated records
2. Start a new record each time the value NEWREC is read/matched but throw out the value NEWREC from the final output
3. Read the DateTime* value and assign as the first field value in each new record for which there is another ITEM* to process until NEWREC is encountered to start another record
4. Read LOC* and assign as the second field value in each new record for which there is another ITEM to process until NEWREC is encountered to start another record
5. Read ITEM* and assign as the third field value


Example:

For file C:\Input.txt (treat all data elements as text, including date/time)

NEWREC
DateTime1
LOC001
ITEM1
ITEM2
ITEM3
ITEM4
NEWREC
DateTime2
LOC002
ITEM1
ITEM2
ITEM3
ITEM4
ITEM5


Create file C:\Output.txt (or Output.csv works, too) formatted thus:

DateTime1, LOC001, ITEM1
DateTime1, LOC001, ITEM2
DateTime1, LOC001, ITEM3
DateTime1, LOC001, ITEM4

DateTime2, LOC002, ITEM1
DateTime2, LOC002, ITEM2
DateTime2, LOC002, ITEM3
DateTime2, LOC002, ITEM4
DateTime2, LOC002, ITEM5


For any code supplied, I truly will attempt to apply it and continue to grow and learn from it. If I can work through this first data-formatting challenge through suggested code, I have multiple circumstances where I will apply the concepts and learning. I'm a systems admin trying to fill some VBS shoes. I learned how to mine WMI and other information using VBS, but formatting data is pretty new to me.

Thanks much--my apologies for any oversights!

=======
Sorry that I can't seem to pull up your what I think was your response, guitarzan:

-----Original Message-----
From: Tek-Tips Forums [mailto:noreply@tek-tips.com]
Sent: Friday, February 12, 2016 7:51 PM
To: ....
Subject: Tek-Tips VBScript Forum: VBScript (or other) to reformat vertical data list elements into horizontal comma-separated records:

guitarzan (Programmer) has responded to the question "VBScript (or other) to reformat vertical data list elements into horizontal comma-separated records:" in the VBScript forum in Tek-Tips.

Come to http://www.tek-tips.com/viewthread.cfm?qid=1761862 to view.

You were notified of this activity because you requested it. To turn off notification, log in to the Tek-Tips site click on the red checkmark next to the "VBScript (or other) to reformat vertical data list elements into horizontal comma-separated records:" thread.

Regards,
Tek-Tips Forums
http://www.tek-tips.com/


RE: v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

I originally asked for the code you had thus far generated and where you were stuck.

We expect you to be the originator and participate in the solution .

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

My response in the last thread (that got deleted) was just asking if this is homework, because that's sure how it looks.

Homework or not, this is not a website where you post specifications and others will write the code for you. You are expected to do the work, and if you run into difficulties, you can post your code and members here will try to help.

RE: v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

(OP)

Maybe this is what a Forum is about:


Thank you, Skip and Guitarzan. I haven't felt this misinterpreted in years. I fully understand the need to work through matters upfront and then enlist help when and where needed. I request the same of those with whom I work that request fixlet relevance language assistance, etc. But I fully recognize the value of providing a code reference similar to the problem that one can reference to then work out and apply the solutions--something that I try to do when I'm the SME.

I am not a student--yet, always will be one. I tried to lay out the objective methodically and somewhat academically, the way I would want it if I'm cold-requesting assistance. I guess that made me seem an school-boy. I wish that I had known my response was simply out-rightly deleted. That would have saved me a bit of time, too.

I fully notice that the following wasn't out-rightly dismissed (mine was, with far better analysis of what I wanted to accomplish) and do wonder why:

nafradws
Rewrite textfile vbscript


You and Skip are clearly moderators of the forum. And I suspect you are both expert VBS coders. I'm sure that I could have applied any similar example set of code that either might provide. And, I expect folks to try to work through issues, first, too. But, I'm NOT a student. I'm employed 27 years with the same firm through many technologies and am trying to step into something completely outside anything that has ever been in my element. After several efforts, all way off, no doubt, I was looking for at least a similar sample set of VBS code from which I could then learn and apply.

I do, sincerely, appreciate the fast responses which you both apparently make weekday and weekend--that says much about your dedication if not expertise. At least I don't feel lonely, there. :)

Thank you, both; good weekend.

-Askovian



RE: v2: VBScript to reformat vertical data list elements into horizontal comma-separated records

...But still no code??

OK, I will show a brief sample that accomplishes the most basic thing you need, which is how to scroll through a text file and extract each line one at a time:

CODE

Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim filename, fso, f, strLine
filename = "C:\Input.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(filename, ForReading)
Do Until f.AtEndOfStream
   strLine = f.ReadLine
   Wscript.echo strLine
   'do something with strLine
   
Loop 

You can use this to build your code and apply your business logic, and if you have further problems you can post your code and state what problems you are having.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close