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

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

Status
Not open for further replies.

Askovian

IS-IT--Management
Feb 12, 2016
2
US
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 [highlight #FCE94F]guitarzan[/highlight] 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)

[highlight #BABDB6]NEWREC[/highlight]
DateTime1
LOC001
ITEM1
ITEM2
ITEM3
ITEM4
[highlight #BABDB6]NEWREC[/highlight]
DateTime2
LOC002
ITEM1
ITEM2
ITEM3
ITEM4
ITEM5


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

[highlight #73D216]DateTime1, LOC001, ITEM1
DateTime1, LOC001, ITEM2
DateTime1, LOC001, ITEM3
DateTime1, LOC001, ITEM4[/highlight]
[highlight #729FCF]DateTime2, LOC002, ITEM1
DateTime2, LOC002, ITEM2
DateTime2, LOC002, ITEM3
DateTime2, LOC002, ITEM4
DateTime2, LOC002, ITEM5[/highlight]

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, [highlight #FCE94F]guitarzan[/highlight]:

-----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 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
 
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,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
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.
 

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.

[highlight #EF2929]I am not a student[/highlight]--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.

[highlight #EF2929]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:[/highlight]

[highlight #AD7FA8]nafradws
Rewrite textfile vbscript[/highlight]

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



 
...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
   [COLOR=#4E9A06]'do something with strLine[/color]
   
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top