Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: VBScript help

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> RE: VBScript help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3] 4   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: VBScript help - 12/12/2006 8:15:09 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Ehvbs,

I just compare the below file using dos command  "FC" ( the problem with the file is "single line")

The process are here....

Compare files 1:271_T_2006-12-05T11-22-17_2tmpF515.txt and 2: 271_T_2006-12-05T11-22-17_2tmpF516.txt

The only difference between these two file is (higlighted in RED)

File Content :271_T_2006-12-05T11-22-17_2tmpF515.txt

ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST01        *061205*1122*U*00401*002109231*0*T*:~GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1~ST*271*0001~BHT*0022*11*BR005415*20060801*1457~HL*1**20*1~NM1*2B*1*TESTCARE CENTER1 CARE PRGRAM*****FI*526002033~HL*2*1*21*1~NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*774800100~HL*3*2*22*0~TRN*2*BR05_FACILITY_Numeric*9526002033~TRN*1*063393337783*0526002033~NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600~N3*5520 TEX TALL CT~N4**MT*217038697**CY*10~DMG*D8*20051126*M~DTP*307*D8*20060628~EB*1*IND*30*MK~DTP*307*D8*20060628~EB*D*IND***ModAK TEIRVERIGIIBLEE for special waiver services~LS*2120~NM1*1P*2~PER*IC**TE*4107671448~LE*2120~EB*D*IND***EPKTT~SE*23*0001~GE*1*2109231~IEA*1*002109231~
~


File Content :271_T_2006-12-05T11-22-17_2tmpF5176.txt


ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST02        *061205*1122*U*00401*002109231*0*T*:~GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1~ST*271*0001~BHT*0022*11*BR005415*20060801*1457~HL*1**20*1~NM1*2B*1*TESTCARE CENTER1 CARE PRGRAM*****FI*526002033~HL*2*1*21*1~NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*774800100~HL*3*2*22*0~TRN*2*BR05_FACILITY_Numeric*9526002033~TRN*1*063393337783*0526002033~NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600~N3*5520 TEX TALL CT~N4**MT*217038697**CY*10~DMG*D8*20051126*M~DTP*307*D8*20060628~EB*1*IND*30*MK~DTP*307*D8*20060628~EB*D*IND***ModAK TEIRVERIGIIBLEE for special waiver services~LS*2120~NM1*1P*2~PER*IC**TE*4107671448~LE*2120~EB*D*IND***EPKTT~SE*23*0001~GE*1*2109231~IEA*1*002109231~
~

in dos prompt

C:\>fc c:\edicomp\271_T_2006-12-05T11-22-17_2tmpF515.txt c:\edicomp\271_T_2006-1
2-05T11-22-17_2tmpF516.txt

Got the below result

Comparing files C:\EDICOMP\271_T_2006-12-05T11-22-17_2tmpF515.txt and C:\EDICOMP
\271_T_2006-12-05T11-22-17_2TMPF516.TXT
***** C:\EDICOMP\271_T_2006-12-05T11-22-17_2tmpF515.txt
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST01         *061205*112
2*U*00401*002109231*0*T*:~GS*HB*MCPEGS*TEST01*2
061205*1122*2109231*X*004010X092A1~ST*271*0001~BHT*0022*11*BR005415*20060801*145
7~HL*1**20*1~NM1*2B*1*TESTCARE CENTER1 CARE PRG
AM*****FI*526002033~HL*2*1*21*1~NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*774800
100~HL*3*2*22*0~TRN*2*BR05_FACILITY_Numeric*952
002033~TRN*1*063393337783*0526002033~NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600~N
3*5520 TEX TALL CT~N4**MT*217038697**CY*10~DMG*
8*20051126*M~DTP*307*D8*20060628~EB*1*IND*30*MK~DTP*307*D8*20060628~EB*D*IND***M
odAK TEIRVERIGIIBLEE for special waiver service
~LS*2120~NM1*1P*2~PER*IC**TE*4107671448~LE*2120~EB*D*IND***EPKTT~SE*23*0001~GE*1
*2109231~IEA*1*002109231~
***** C:\EDICOMP\271_T_2006-12-05T11-22-17_2TMPF516.TXT
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST02        *061205*1122
*U*00401*002109231*0*T*:~GS*HB*MCPEGS*TEST01*20
61205*1122*2109231*X*004010X092A1~ST*271*0001~BHT*0022*11*BR005415*20060801*1457
~HL*1**20*1~NM1*2B*1*TESTCARE CENTER1 CARE PRGR
M*****FI*526002033~HL*2*1*21*1~NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*7748001
00~HL*3*2*22*0~TRN*2*BR05_FACILITY_Numeric*9526
02033~TRN*1*063393337783*0526002033~NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600~N3
*5520 TEX TALL CT~N4**MT*217038697**CY*10~DMG*D
*20051126*M~DTP*307*D8*20060628~EB*1*IND*30*MK~DTP*307*D8*20060628~EB*D*IND***Mo
dAK TEIRVERIGIIBLEE for special waiver services
LS*2120~NM1*1P*2~PER*IC**TE*4107671448~LE*2120~EB*D*IND***EPKTT~SE*23*0001~GE*1*
2109231~IEA*1*002109231~
*****

I do understand why its not pin point the exact change because its consider as single line.

But i did the other way...just unwrap the both file like this

ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST02        *061205*1122*U*00401*002109231*0*T*:
GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1
ST*271*0001
BHT*0022*11*BR005415*20060801*1457
HL*1**20*1
NM1*2B*1*TESTCARE CENTER1 CARE PRGRAM*****FI*526002033
HL*2*1*21*1
NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*774800100
HL*3*2*22*0
TRN*2*BR05_FACILITY_Numeric*9526002033
TRN*1*063393337783*0526002033
NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600
N3*5520 TEX TALL CT
N4**MT*217038697**CY*10
DMG*D8*20051126*M
DTP*307*D8*20060628
EB*1*IND*30*MK
DTP*307*D8*20060628
EB*D*IND***ModAK TEIRVERIGIIBLEE for special waiver services
LS*2120
NM1*1P*2
PER*IC**TE*4107671448
LE*2120
EB*D*IND***EPKTT
SE*23*0001
GE*1*2109231
IEA*1*002109231

and did a comparision...now i got the below result

Comparing files C:\EDICOMP\271_T_2006-12-05T11-22-17_2tmpF515.txt and C:\EDICOMP
\271_T_2006-12-05T11-22-17_2TMPF516.TXT
***** C:\EDICOMP\271_T_2006-12-05T11-22-17_2tmpF515.txt
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST01         *061205*112
2*U*00401*002109231*0*T*:
GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1
***** C:\EDICOMP\271_T_2006-12-05T11-22-17_2TMPF516.TXT
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST02        *061205*1122
*U*00401*002109231*0*T*:
GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1
*****

when i ran the above file (Unwrapped files) thru my script it gives the below result.

Common items in Current and Obsolete:
GS*HB*MCPEGS*TEST01*20061205*1122*2109231*X*004010X092A1
ST*271*0001
BHT*0022*11*BR005415*20060801*1457
HL*1**20*1
NM1*2B*1*TESTCARE CENTER1 CARE PRGRAM*****FI*526002033
HL*2*1*21*1
NM1*1P*2*TESTTEST FANCYS REPUBLICK*****SV*774800100
HL*3*2*22*0
TRN*2*BR05_FACILITY_Numeric*9526002033
TRN*1*063393337783*0526002033
NM1*IL*1*PXTVNO*VZGEXR*A***MI*46803327600
N3*5520 TEX TALL CT
N4**MT*217038697**CY*10
DMG*D8*20051126*M
DTP*307*D8*20060628
EB*1*IND*30*MK
DTP*307*D8*20060628
EB*D*IND***ModAK TEIRVERIGIIBLEE for special waiver services
LS*2120
NM1*1P*2
PER*IC**TE*4107671448
LE*2120
EB*D*IND***EPKTT
SE*23*0001
GE*1*2109231
IEA*1*002109231

Total no. of common items: 27
----------------------

Items in Current but not in Obsolete:
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST01         *061205*1122*U*00401*002109231*0*T*:
Total no. of items in Current: 1
----------------------

Items in Obsolete but not in Current:
ISA*00*          *00*          *ZZ*526002033MKPT  *ZZ*TEST02        *061205*1122*U*00401*002109231*0*T*:
No. of items only in Obsolete: 1
---------------------

Now i will go and see your Sample (use dictionaries to compare two arrays) to get more ideas.

Thanks
Ashok

(in reply to ehvbs)
 
 
Post #: 41
 
 RE: VBScript help - 12/12/2006 8:54:48 AM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

I owe you an apology. My suspicion against your code was based on a 'read only'
code walk thru and I realize now, that it was false. Working with your code to
integrate it into EdiComp-03.vbs (following soon) made me see how it really works.

So don't spend time on seeking errors that exist only in my misconception. I
really regret my blunder and hope you will forgive me.

ehvbs

(in reply to ehvbs)
 
 
Post #: 42
 
 RE: VBScript help - 12/12/2006 9:27:26 AM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Ok, thinking is nice, but sometimes coding is more fun:

(1) copy EdiComp-02.vbs to EdiComp-03.vbs (could be done by your trainee)

(2) Add a new experimental function EdiComp-03.vbs

''#             frsLoop   - first try at compare loop
''#             compTwo   - compare two files with two methods
''#             ?         - ?

     Case "frsloop"
       nRVal = frsLoop()
     Case "comptwo"
       nRVal = compTwo()

' ############################################################################
''# compTwo - compare two files with two methods
' ############################################################################

Function compTwo()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, compTwo() was called."

  compTwo = nRVal
End Function

' ############################################################################
''# cpeMe - copy/paste/edit template
' ############################################################################

(3) Don't think ("I have done it correctly") but test:

        cscript edicomp-03.vbs compTwo
        ok, compTwo() was called.

(4) What have we done? To recap it, we have to compare EdiComp-02.vbs vs.
    EdiComp-03.vbs. Don't plan/code yourself, use other people's work
    instead:


      

(5) The first part of the output looks usable, the second is definitely not so nice.
    Don't give up on the "use someone else' compare" too early. There are other diff
    tools and FC may be taught to do better by giving it some options (experiment
    with fc /? and some sample files you are interested in.
    My unix diff gave

        11a12
        > ''#             compTwo   - compare two files with two methods
        51a53,54
        >      Case "comptwo"
        >        nRVal = compTwo()
        277a281,291
        > ''# compTwo - compare two files with two methods
        > ' ############################################################################
        >
        > Function compTwo()
        >   Dim nRVal : nRVal = 1 ' assume bad
        >   WScript.Echo "ok, compTwo() was called."
        >
        >   compTwo = nRVal
        > End Function
        >
        > ' ############################################################################

    for the same task. Much better. I showed the rather long example to drive home
    one important fact about "using other people's work": It may require some efforts
    (installing, learning, interfacing, ...).

(6) But I promised code! Ok, let's do a simplistic "compare two files by two methods"
    (I silently changed my German-English "compare two files with two methods"):


      

(7) Now we have to tackle those nasty last lineendings (especially evil if
    they aren't there!) and do something about the poor doDicComp(). For this
    I will use other people's work (I start to get tired). First let's
    exploit ebgreen:

         If vbCrLf = Right( sFrsAll, 2 ) Then ' made save with ebgreen's help
'           strText = Left(objFSO.OPenTextFile("C:\temp\testout.txt").ReadAll(), Len(objFSO.OPenTextFile("C:\temp\testout.txt").ReadAll())-2)
            sFrsAll = Left( sFrsAll, Len( sFrsAll ) - 2 )
         End If

    Then let's exploit a whole group of people:

         aFrs = Split( sFrsAll, vbCrLf )   ' wouldn't be save without aburt, ebgreen & ehvbs
         aSec = Split( sSecAll, vbCrLf )

      The TrimWSRE() function was copied from aburt's project:


      

    The mergeArrays() function I posted on 12/8/2006 to this topic. Adding it
    to EdiComp-03.vbs and 'enhancing' doDicComp() to

        Sub doDicComp( aFrs, aSec )
          Dim aDiffs : aDiffs = mergeArrays( aFrs, aSec )
          Dim nIdx
          For nIdx = 0 To UBound( aDiffs )
              WScript.Echo aDiffs( nIdx, 0 )
              WScript.Echo aDiffs( nIdx, 1 )
          Next
        End Sub

    will result in an terrible output. You should really run the 'Phil and his
    friends' sample/test code to (re)gain any confidence in mergeArrays().

(8) Partly by design, partly by luck the code/processing and the layout/output
    related features of doDicComp() and its helper mergeArrays() are separated
    fairly well. mergeArrays() does the heavy work, doDicComp() just asks
    mergeArrays() for the results, and does a - very bad - job of showing
    them to the user.
    [THIS PART WILL BE CONTINUED LATER]

(9) Ok, Ashok is getting impatient. I can understand that and I will try to
    show how to integrate his code (step by step) into EdiComp-03.vbs.
    The first part is easy: just the same procedure as for compTwo():

''#             compTwo   - compare two files with two methods
''#             compAshok - compare two files - by Ashok (who should improve this line)
''#             ?         - ?

     Case "comptwo"
       nRVal = frsLoop()
     Case "compashok"
       nRVal = compAshok()

' ############################################################################
''# compAshok - compare two files with  - by Ashok (who should improve this line)
' ############################################################################

Function compAshok()
  Dim nRVal : nRVal = 1 ' assume bad
  WScript.Echo "ok, compAshok() was called."

  compTwo = nRVal
End Function

(10) Next version of compAshok() and first version of doAshokComp():


      


      

(11) I pasted Ashok's code over the WScript.Echo line and commented out the whole
     block. Because I'm pressed for time, I will do a very ruthless reworking of
     Ashok's code. It's rude and unfair, because I will change things not because
     they are wrong or bad, but because I can work faster my way. Furthermore
     I will delete some code (the logging) to make doAshokComp() more compatible
     with the (current state of) EdiComp-03.vbs. Bear that in mind (especially you,
     Ashok) when you look at my evil work (in the complete script at the end of this
     monster posting). During this work I realized that my reading/interpreting
     of the code was wrong; the code does a good job comparing two files.

(12) As soon as I realized this, I switched to "setup test data" using two (later
     modified) copies of the 'de-secreted' data of Ashok's posting from 06:40.
     I was glad to get output like this:
     

      

(13) [This number can't be random] My current version of EdiComps-03.vbs:


      

(14) My plans for tomorrow:

     (1) Some words about the different compare methods
    
     (2) First try at a decent output/report format
    
     (3) Merging Link search and comparision in a first attempt
         of doTheRealWork()
 

(in reply to ehvbs)
 
 
Post #: 43
 
 RE: VBScript help - 12/12/2006 9:08:50 PM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

a question concerning "what to compare to what" that relates to my cryptic

'        store Link an Path in Dictionary (todo: check for duplicates!)

This is the test case:

4 files in A, A2 and A4 contain Link BR05_FACILITY_Numeric; 2 files
in B, B2 contains BR05_FACILITY_Numeric; frsLoop compares B2 vs
A4 but not B2 vs A2.

cscript EdiComp-04.vbs frsLoop
ok, frsLoop() was called.
Processing all files in Folder .\FolderA
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test1.edi
Link: |2|BR01_FACILITY_Numeric|9526002033|
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test2.edi
Link: |2|BR05_FACILITY_Numeric|9526002033|
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test3.edi
Link: |2|BR-A-3_FACILITY_Numeric|9526002033|
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test4.edi
Link: |2|BR05_FACILITY_Numeric|9526002033|
------------------------------------------------------------
Processing all files in Folder .\FolderB
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderB\test1.edi
Link: |2|BR01_FACILITY_Numeric|9526002033|
Link BR01_FACILITY_Numeric found.
We have to compare:
  C:\wis\_vbs\0506\dev\forum\EdiComp\FolderB\test1.edi
  C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test1.edi
  Easy: the files are identical!
------------------------------------------------------------
Searching in C:\wis\_vbs\0506\dev\forum\EdiComp\FolderB\test2.edi
Link: |2|BR05_FACILITY_Numeric|9526002033|
Link BR05_FACILITY_Numeric found.
We have to compare:
  C:\wis\_vbs\0506\dev\forum\EdiComp\FolderB\test2.edi
  C:\wis\_vbs\0506\dev\forum\EdiComp\FolderA\test4.edi
  Now do a detailed compare!


What do you think: Is that a bug or a feature? Do we have to compare
one folder B file to more than one Folder A file? Or are duplicate Links
in Folder A to be considered as fatal errors?

(in reply to ehvbs)
 
 
Post #: 44
 
 RE: VBScript help - 12/13/2006 1:07:39 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Ehvbs,

Oh my god you are thinking all the possibilities huh!( i need to learn this from you ) to write the best code...

Ok here is the Answer for your question

******************************Question*********************************

This is the test case:

4 files in A, A2 and A4 contain Link BR05_FACILITY_Numeric; 2 files
in B, B2 contains BR05_FACILITY_Numeric; frsLoop compares B2 vs
A4 but not B2 vs A2.

**************************************************************************

**********************Answer**********************************************


I need  to explain little bit about the background process.

we know it has two folder A and B.

here  the easy part is Folder B have only 74 files that are always constant(unfotunately file names are dynamic) we call those files are BizzRule files.

for example( in Folder B)

 fileB1 has BR01_facility_code
 fileB2 has BR01_facility_code
.
.
.
.
fileB74 has BR74_facility_code


Now come to FolderA...basically system generates these files based on input....

For Example:

my input is 5 file and i will get 5output files...ex:A1,A2,A3,A5,A5.

Back to your example

Now A2 and A4 contains : BR02_facility_code
A1 and A3 contains: BR01_facility_code
A5 contains : BR05_facility code


here we need to compare A2 and A4 VS Only one file in B folder file ...ex:FileB5 has (BR02_facility Code)

A2 VS B5 ,A4 VS B5.

likewise for other file...

what am trying to say here is you will find only one file in Folder B ,it wont be any duplicate in folder B.but Folder A has many files.

Right now we eliminate duplacte in folder A manually...so basically we don't have duplicates.

is that my answer make you clear.

I will go thru the rest of you reply.

Thanks
Ashok

(in reply to ehvbs)
 
 
Post #: 45
 
 RE: VBScript help - 12/13/2006 1:42:32 AM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

Please check:

   Folder B  (BizRule)
       ca 74 fairly constant files with one unique Link each
       (fileB2 has BR01_facility_code should have been  fileB2 has BR02_facility_code)

       should be treated as we treated FolderA upto now: collect 74 different Links in a dictionary

   Folder A  (files generated from user input)
       we care only for: if a file has a Link and we have a file with that Link in folder B, we do
       the compare
       Folder A files without Links or with Links not found in Folder B  (BizRule) may be reported
       as dubious
 
       should be treated as we treated FolderB upto now

How does that relate to your use of the names "current" and "obsolete"?
 

(in reply to ashok_ganeshs)
 
 
Post #: 46
 
 RE: VBScript help - 12/13/2006 2:05:38 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Ehvbs,

Current i assumed as Folder A file and obsolete i assumed as Folder B file.

i need to change that based on file names indeed.

**********************************Quest**************************************************
Folder A  (files generated from user input)
       we care only for: if a file has a Link and we have a file with that Link in folder B, we do
       the compare
       Folder A files without Links or with Links not found in Folder B  (BizRule) may be reported
       as dubious
 
       should be treated as we treated FolderB upto now
**********************************************************************************************
*************************************ANSW**************************************************
if we get a file in FolderA ,i assure 101% it will be in Folder B also.ofcourse you code is already handle the other situation.

If folderA file is not in folder B (No FolderA file to compare to this FolderB File)

I just sent a real BIZRULE Blueprint(consider as FolderB Files) to PM.

I will make some duplicates and post it in this forum...will help for other users.

**********************************************************************************************
*************************************Question**************************************************
 Please check:

   Folder B  (BizRule)
       ca 74 fairly constant files with one unique Link each
       (fileB2 has BR01_facility_code should have been  fileB2 has BR02_facility_code)

**********************************************************************************************
*************************************ANSW**************************************************
That's what we don't know what FileB2 contains it might have BR01_facility_code or BR02_facility_code some thing llike that.

That's why we are using search in TRN Segment to find out.The file in folder B suppose to be based on TRN value (ex: BR01_Facility_Code) then the file name is BR01_facility_code.txt.

But the requirement got changed...now we don't wanna rename the file manually in folderB files.

you might understand if you see the Blueprint of my BizRule.

Thanks
Ashok
 

(in reply to ehvbs)
 
 
Post #: 47
 
 RE: VBScript help - 12/13/2006 2:33:29 AM   
  ehvbs

 

Posts: 2012
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

my mind boggles! I have to study your file & think. In the meantime: Here is what I prepared:

This is EdiCompRpt.txt