Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


need to find length of line within array field

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60077
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 need to find length of line within array field - 5/11/2008 3:45:27 PM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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 >
 
 
Post #: 1
 
 RE: need to find length of line within array field - 5/12/2008 1:58:12 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
So all lines should be 135 characters?  If they are longer are they supposed to be broken up to be 135 characters each?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chriswebb18)
 
 
Post #: 2
 
 RE: need to find length of line within array field - 5/12/2008 2:09:47 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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.

something like adding strText = Replace(strText, VbCrLf, Space(135 - Len(strLine) & VbCrLf)

after objNewFile goes in for reading, but before is replaced with $$ and split for array

< Message edited by chriswebb18 -- 5/12/2008 2:37:46 AM >

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: need to find length of line within array field - 5/12/2008 2:23:40 AM   
  dm_4ever


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                                                                                  

Let us know how the other attempt works for you.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chriswebb18)
 
 
Post #: 4
 
 RE: need to find length of line within array field - 5/12/2008 2:49:19 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
ok it takes the input lines:

REC12400621     5928      095119      MME02/15/2008           PTGARSTEVE                    C
CARGLE                             1533 FAIRVIEW ROAD                 ELLENWOOD

REC12400621     5928      095119      MME02/15/2008           GREMP
STEVE'S TREE SERVICE               SELF EMPLOYED

would become


REC12400621     5928      095119      MME02/15/2008           PTGARSTEVE                    C CARGLE                             1533 FAIRVIEW ROAD                 ELLENWOOD

REC12400621     5928      095119      MME02/15/2008           GREMP STEVE'S TREE SERVICE               SELF EMPLOYED

but the

REC12400621     5928      095119      MME02/15/2008           PTGARSTEVE                    C
CARGLE                             1533 FAIRVIEW ROAD                 ELLENWOOD

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 >

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: need to find length of line within array field - 5/12/2008 3:09:42 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
i then tried using

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 >

(in reply to chriswebb18)
 
 
Post #: 6
 
 RE: need to find length of line within array field - 5/12/2008 3:36:55 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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

(in reply to chriswebb18)
 
 
Post #: 7
 
 RE: need to find length of line within array field - 5/12/2008 3:38:04 AM   
  dm_4ever


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.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chriswebb18)
 
 
Post #: 8
 
 RE: need to find length of line within array field - 5/12/2008 3:47:20 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: need to find length of line within array field - 5/12/2008 3:51:05 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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.

(in reply to chriswebb18)
 
 
Post #: 10
 
 RE: need to find length of line within array field - 5/12/2008 4:07:44 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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.

(in reply to chriswebb18)
 
 
Post #: 11
 
 RE: need to find length of line within array field - 5/12/2008 4:27:12 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
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.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chriswebb18)
 
 
Post #: 12
 
 RE: need to find length of line within array field - 5/12/2008 4:31:55 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I think I gotcha now.... so instead of doing this

Dim strText : strText = objInputFile.ReadAll
objInputFile.Close

You will need to go through each line in the text file...something like

Dim strText, strTemp, intLen
Do Until objInputFile.AtEndOfStream
   strTemp = objInputFile.ReadLine
   intLen = Len(strTemp)
   If intLen < 135 Then strTemp = strTemp & Space(135 - Len)
   strText = strText & strTemp & VbCrLf
   strTemp = ""
Loop
objInputFile.Close

This should make sure each line has 135 characters prior to working with it....

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to chriswebb18)
 
 
Post #: 13
 
 RE: need to find length of line within array field - 5/12/2008 4:52:19 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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 >

(in reply to dm_4ever)
 
 
Post #: 14
 
 RE: need to find length of line within array field - 5/12/2008 6:17:24 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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.


      

(in reply to chriswebb18)
 
 
Post #: 15
 
 RE: need to find length of line within array field - 5/12/2008 6:52:11 AM   
  chriswebb18

 

Posts: 71
Score: 0
Joined: 4/7/2008
Status: offline
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.

this website helped a lot with regular exp. btw if anyone needs some help
http://www.scribd.com/doc/193608/regular-expressions-cheat-sheet

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 >

(in reply to chriswebb18)