All Forums >> [Scripting] >> WSH & Client Side VBScript >> need to find length of line within array field Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
alright, i had a lot of help with this code the first time around, and i have been messing with it a lot since. i had a file that i needed to combine information from multiple lines into one, but still keep records seperated. http://visualbasicscript.com/m_58874/mpage_1/key_/tm.htm#58874 this was the original post, it is a dead thread, though, so i started this one. Sorry if i broke some rules there. anyway, the lines that i was combining were supposed to all be fixd length at 135 characters. apparently, for some reason, the program i am getting this file(input for this vbscript) is not keeping spaces at the end of the line. i thought a simple space(135-Len(strLine)) would work, but i had so much trouble, i finally figured out that its because each strLine is from record no to record no(the regexp in script REC\d{8}), not from crlf to crlf. any ideas on how to get a Len(each individual line) without screwing up the array, id love it. i tried changing the array to split at crlf, but then it make things horrible at the end of script, since the crlf is critical and everything else is working beautiful.
lines 38/39 are commented. i was only using to find out why it was not allowing the space command.
< Message edited by chriswebb18 -- 5/11/2008 11:14:25 PM >
none of the lines are over 132 char (before split into array) and never will be.
-edit - maybe this would be easier i didnt even think about it. before it splits into the array and is searched for the regex and everything else; can we go through and make every line 135 char. let me work on it this way, ill post when i have something, let me know if you find already have something.
Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I'm still a bit confused as to what the end result should be.
Should a line like this SEM10 REC12400061 4130 EO017512 MMV02/14/2008 SEM10DISABLED 770 7759188 0 02/13/20088481 2SMITH JOHN D 1 BB023SVZ100323412 000SVZ834 BLUE CROSS 2 MM010256905651A MEDICARE 3 MM012256905651A PRO FEE/MEDICARE 0 000
become.... SEM10 REC12400061 4130 EO017512 MMV02/14/2008 SEM10DISABLED 770 7759188 0 02/13/20088481 2SMITH JOHN D 1 BB023SVZ100323412 000SVZ834 BLUE CROSS 2 MM010256905651A MEDICARE 3 MM012256905651A PRO FEE/MEDICARE 0 000
REC12400621 5928 095119 MME02/15/2008 GREMP STEVE'S TREE SERVICE SELF EMPLOYED
need to be 135 chars before joined. not sure where the SEM10 is coming
FROM ORIGINAL POST on different thread(input file):
Each REC... and the lines before the next REC... is one patient. each of the lines from input must equal 135 before joining, but each patient needs to be on one line. i added the strText = Replace(strText, VbCrLf, Space(135 - Len(strLine) & VbCrLf) before the array, but my columns are still not lining up, once the lines are joined, everything must line up, looking like columns, but not really a column since in txt. sorry so long hope this helps
< Message edited by chriswebb18 -- 5/12/2008 2:51:43 AM >
For Each strLine In strText strLine = Replace(strLine, VbCrLf, Space(135 - Len(strLine)) & VbCrLf Next
with no luck is giving me object not a collection error. i assume since the text file is not split into seperate lines when it is read. im not sure exactly how that works
< Message edited by chriswebb18 -- 5/12/2008 3:10:52 AM >
Ok , i am very new to arrays, and dm4ever helped massively with the array in this script. i tried to duplicate it like this(I know the more i mess with this script, the sloppier looks, sorry):
i am still getting error that object is not a collection when referencing strLine
Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I must be more tired than I thought since I still don't really follow. For example the last line in the example text would be well over 135 characters
REC12400061 4130 EO017512 MMV02/14/2008 PTGARRONNIE GENE TURNER 128 MARTIN ROAD JACKSON GA 302333648 JACKSON GA302333648 770 5041120 S 07/15/1954M256905651 02/13/20088481 2SMITH JOHN D 1 BB023 SVZ100323412 000SVZ834 BLUE CROSS 2 MM010256905651A MEDICARE 3 MM012256905651A PRO FEE/MEDICARE 0 000
Is the 135 characters for formatting purposes? Is this output file going to be used by something else or is it a way to clean up the data into an organized and easily readable file? If it is only for reporting/viewing purposes, why not remove the spaces and replace them with commas to create a comma separated file that can then be easily viewed in Excel?
Sorry for all the questions...I'm a bit slow today.
the file will be fed into a database that picks up information that is set to a certain char position. ie patient record is char 1. action taken is char 43. and so on. once the lines are combined, they will be over 135 chars should be from 700-1000. but, before they are joined - 135 chars. like this:
REC12400061 4130 EO017512 MMV02/14/2008 PTGARRONNIE GENE (##ADD SPACES TO MAKE 135) TURNER 128 MARTIN ROAD JACKSON GA 302333648 (##ADD SPACES TO MAKE 135) JACKSON GA302333648 770 5041120 S 07/15/1954M256905651 02/13/20088481 2SMITH JOHN D 1 BB023 (##ADD SPACES TO MAKE 135) SVZ100323412 000SVZ834 BLUE CROSS (##ADD SPACES TO MAKE 135) 2 MM010256905651A MEDICARE (##ADD SPACES TO MAKE 135) 3 MM012256905651A (##ADD SPACES TO MAKE 135) PRO FEE/MEDICARE (##ADD SPACES TO MAKE 135) 0 000 (##ADD SPACES TO MAKE 135)
...then the text is split in the array, where it removes the car return line feed. and the final line is around 1000 chars. not sure if i explained that well enough there, let me know
i also was planning on doing a comma delimited file which would be easier to make, but some of the columns dont have spaces between, so i am not sure how to insert them there. i.e. \/(rec1 and 2400061 are diff fields) \/(mmv is seperate from the date)\/(ptgar is not the same field as ronnie) REC12400061 4130 EO017512 MMV02/14/2008 PTGARRONNIE GENE
it is way too irregular to make any kind of standard script to find where commas go, originally i thought wherever more than 1 space replace with comma, but as seen above would not work.
ok, i have tried a few things...unsuccessfully, but can we just try to take and space the lines out without worrying about combining them or anything else, just make each line = 135 char then i can try to make my current script run on the tail end of that.
I think the problem is that you don't need the complete line to be 135 chars. What you need is for each of the fields in the line to have the same number of characters.
ok, i have found the problem. if you notice at the end of some records, there are sometimes lines with just spaces and 0's or with a random 568 or other numbers: those are the only lines that occasionally go over 135 char. i tried using rtrim before running space, but there are 0' to the far right which are messing it up... anyway. we do not need the lines that only have spaces and numbers. I am once again trying to make this more difficult... Can we make a loop ie
- edit - or maybe detect like this: if (no alpha chars) instead of (only #'s and " "'s) either way i am having trouble finding the syntax to determine what chars the line contains
< Message edited by chriswebb18 -- 5/12/2008 4:55:19 AM >
maybe using a regex like this: is not working, is this the proper syntax for the regex.pattern = (a-z). i am having a hard time on finding info on this. i have see the \d{} to search for numbers, but not sure for a-z.
ok i think it is near perfect. i copied the array strucure from the first initial script and tweaked it. i did the second part seperate then pasted it on the end, so its a little sloppy. the only thing im getting is that, every once in a while i get a line that is not brought up properly.
the problem i have is this strange character that is in the input document, it seems to cause a line break. it looks like a black box with 2 F's in it. "" is what it looks like outside of notepad.
i tried insterting strText = Replace(strText, "", " ") before the first array and it removes the character, but is still giving a new line there.
CODE USED so far
< Message edited by chriswebb18 -- 5/12/2008 7:31:37 AM >