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: [1] 2 3 4   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: VBScript help - 12/6/2006 5:42:54 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
First of all i would like to thanks for your reply.

I am not sure i explained the scenario correctly or not...but here is the one i will explain little bit more about that.

I have folder A in for ex: C:\271TestFile_folderA

It has 10 files for example : 271_T_2006-12-05T11-22-17_2tmpF513.txt like that

here is the content of that file for 271_T_2006-12-05T11-22-17_2tmpF513.txt

BR005415*20060801*1457~HL*1**20*1~NM1*2B*1*XYZ*****FI*526002033~HL*2*1*21*1~NM1*1P*2*TEST00001*****SV*774800100~HL*3*2*22*0~TRN*2*BR05_FACILITY_Numeric*9526002033~TRN*1*063393337783*0526002033~NM1*IL*1*TESST*TESTE*A***MI*46803327600

like wise i have 10 different files each files have different value in the TRN segment (Highlited in Red)...like wise i have files in Floder B also

Ex:  C:\271TestFile_folderB

File : 271_T_2006-12-05T11-45-38_3tmp9ED2.txt

Basically what i suppose to do

1) Read the file in the folderA and find it out the Highligted Value in RED(*BR05_FACILITY_Numeric*) and check the same value in folder B file.
Example :
271_T_2006-12-05T11-22-17_2tmpF513.txt file in Folder A has that value and 271_T_2006-12-05T11-45-38_3tmp9ED2.txt file in folder B also have the same value then compare both files line by line and generate the report.


hope i explained the scenario clearly...


Thanks in Advance

Ashok
 
 
Post #: 1
 
 RE: VBScript help - 12/6/2006 6:11:47 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
First, are the files named the same in each folder or is there a pattern that would match a file in folder A with a specific file in folder B?

_____________________________

"... 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 ashok_ganeshs)
 
 
Post #: 2
 
 RE: VBScript help - 12/6/2006 6:41:53 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ashok_ganeshs,

please help me to help you by answering these questions:

  (1) Are those files EDI files as explained e.g. here:
        http://en.wikipedia.org/wiki/Electronic_Data_Interchange
        http://members.aol.com/getmydata/pskb/ANSI-X12-EDI-Format.htm
        
  (2) Can you check/modify this pseudo code:
 
      For Each File In FolderA
          LinkValueA = get_BR05_FACILITY_Numeric( File )
          dicLink.Add LinkValueA, File.Path
      Next
      For Each File In FolderB
          LinkValueB = get_BR05_FACILITY_Numeric( File )
          If dicLink.Exists( LinkValueB )
             doDetailedCompare File, dicLink( LinkValueB )
             dicLink.Remove LinkValueB
          Else
             Report: No FolderA file to compare to File.Path
          End If  
      Next
      For Each Link In dicLink
          Report: No FolderB file to compare to dicLink( Link )
      Next
     
  (3) What should get_BR05_FACILITY_Numeric( File ) return, if
      the content of the file looks like:
     
         [whatever] ~TRN*2*BR05_FACILITY_Numeric*9526002033~ [whatever]
        
      i.e. what should be looked for in the FolderB files?  
        
  (4) Any ideas a about the doDetailedCompare()?
 

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: VBScript help - 12/6/2006 7:22:33 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thanks for your reply Ebgreen.

File names are dynamic in both folders(A and B).

Ex:271_T_2006-12-05T11-22-17_2tmpF513.txt this is the way it name the file.

Thanks
Ashok S Ganesh

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: VBScript help - 12/6/2006 7:23:35 AM   
  ashok_ganeshs

 

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

Thanks a lot for your reply

Here are the Answers for your questions

1)Yes exactly Same (if you wanna see the actual file i can send the whole stuff)

2)I will try if you guide me bcoz am new to Psuedo

3)am looking the same(EX:BR05_FACILITY_Numeric) in Folder B file then i will compare those two files line by line

4) honestly NO

is this make clear...

Thanks
Ashok S Ganesh

(in reply to ashok_ganeshs)
 
 
Post #: 5
 
 RE: VBScript help - 12/6/2006 7:24:40 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
It sounds like ehvbs is as usual more versed on the specifics of your issue. If he does not have a solution for you however I can help with a purely text-parsing based solution for you.

_____________________________

"... 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 ashok_ganeshs)
 
 
Post #: 6
 
 RE: VBScript help - 12/6/2006 7:27:39 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thank you so much to care about my issue..

Thanks
Ashok S Ganesh

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: VBScript help - 12/6/2006 8:25:09 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ashok_ganeshs,

the Wikipedia exlpains "pseudo code" much better than I could:

     http://en.wikipedia.org/wiki/Pseudocode

My aim was to convey a rough sketch of how I think the comparison should work. The
'highlights':

    look at each file in folderA
    get something from the file that allows to determine which file in folderB should be compared

I still don't know what I have to get from a file to find the corresponding file. Is it just the
string "BR05_FACILITY_Numeric"? If yes - what would a second file in folderA contain that
should be searched in the files in folderB?

(in reply to ashok_ganeshs)
 
 
Post #: 8
 
 RE: VBScript help - 12/7/2006 12:52:15 AM   
  ashok_ganeshs

 

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

Your Idea is exactly what i want..

You said you don't know what string (*"BR05_FACILITY_Numeric"*) need to search in the file , i just upload the whole EDI  file and sent a PM to you,bcoz i can't disclose the file public,"Administrators" sorry for that.

basically  the concept is here i need to find "TRN" String first then go to that line you can see three stars, the values are in between the stars right...so i need to pick the value in between second and third stars (i mean *BR05_FACILITY_Numeric*) based on that value do the search on the other folder files and compare the files...

~TRN*2*BR05_FACILITY_Numeric*9526002033~

are you with me now...


Thanks
Ashok

(in reply to ehvbs)
 
 
Post #: 9
 
 RE: VBScript help - 12/7/2006 1:13:28 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi ashok_ganeshs,

thanks for your info and the file. I'll work on it, but it will take some time (let's say
5-8 hours).

ehvbs

(in reply to ashok_ganeshs)
 
 
Post #: 10
 
 RE: VBScript help - 12/7/2006 2:06:46 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thank thanks thanks a lot Ehvbs.

Thanks
Ashok

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: VBScript help - 12/7/2006 5:08:50 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
per reply in pm:

Assuming the files are formatted the same this is fairly straight forward.

Pseudocode:
read in file one
parse out the fields (using the split() function, that would be the fastest)
assign field to a variable
read in file two
parse out the fields (using the split() function, that would be the fastest)
assign field to a variable

compare the two fields

i may be a bit behind on this, but im starting finals so i wont have much free time for awhile

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to ashok_ganeshs)
 
 
Post #: 12
 
 RE: VBScript help - 12/7/2006 5:26:41 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I have a couple of suggestions for you ashok_ganeshs:

  1. Sending out private messages to members with the same question you posted in the main forum is considered rude, please dont do it again. (At least not to me)
  2. This forum is for helping people that already have existing code, not for writing a script from scratch for everyone that asks a question
    1. NB: if a member wants to do it, that is up to them, I generally dont unless I see an effort from the person asking the question to at least try to write it themselves.
  3. I may be wrong, but it sounds like you dont have any (or little) experience coding or writing scripts, I highly suggest learning this because (even if the script that someone else writes for you works) at some point in the future there is a good possibility that you may have to modify it.

VBScript Tutorial
http://www.w3schools.com/vbscript/default.asp
Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/ddfa5183-d458-41bc-a489-070296ced968.asp
A script I wrote for a scripting class
http://visualbasicscript.com/m_27365/tm.htm

This forum is about helping each other, but there are people that try to take advantage of that without at least attempting to help themselves first. They get help and then disappear, never to be seen again. I hope that you stay around, learn, and help others like you have been helped.


I'll get off my soapbox now...


_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to kirrilian)
 
 
Post #: 13
 
 RE: VBScript help - 12/7/2006 5:37:59 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Am sorry Kirrilian my intention is not to bothering you...

i got copule of your reply in my Inbox so i replied back to that.

as of now i just wrote the comparision code for your view...

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

Const ForReading = 1
Const ForAppending =8

'Change the path here based on the INPUT and OUTPUT files
strCurrent = "C:\Copy_TEST\*.*"
strObsolete = "C:\Copy_TEST\*.*"
strLogFile = "C:\Copy_TEST\CompList.log"


Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")


Set objCurrent = objFSO.OpenTextFile(strCurrent, ForReading)
Set objObsolete = objFSO.OpenTextFile(strObsolete, ForReading)


Set objLogFile = objFSO.CreateTextFile(strLogFile, True)
Set objLogFile = Nothing


Set objLogFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)


Set objDicCurrent = CreateObject("Scripting.Dictionary")
Set objDicObsolete = CreateObject("Scripting.Dictionary")


intCurrent = 0
Do While objCurrent.AtEndOfStream <> True
    strNextLine = objCurrent.Readline
    objDicCurrent.Add intCurrent, strNextLine
    intCurrent = intCurrent + 1
Loop
objCurrent.Close
ColKeysCurrent = objDicCurrent.Keys


intObsolete = 0
Do While objObsolete.AtEndOfStream <> True
    strNextLine = objObsolete.Readline
    objDicObsolete.Add intObsolete, strNextLine
    intObsolete = intObsolete + 1
Loop
objObsolete.Close


intTotalItems = objDicCurrent.Count


objLogFile.WriteLine "Common items in Current and Obsolete:"


intItemsCount = 0
For Each objCurrent In objDicCurrent
        strCurrent = objDicCurrent.Item(objCurrent)
        For Each objObsolete In objDicObsolete
                strObsolete = objDicObsolete.Item(objObsolete)
                If strCurrent = strObsolete Then
                        objLogFile.WriteLine strCurrent
                        intItemsCount = intItemsCount + 1
                        objDicCurrent.Remove(objCurrent)
                        objDicObsolete.Remove(objObsolete)
                        Exit For
                End If
        Next
Next
objLogFile.WriteLine "Total no. of common items: " & intItemsCount


intTotalItems = objDicCurrent.Count
objLogFile.WriteLine "----------------------"
objLogFile.WriteLine ""
objLogFile.WriteLine "Items in Current but not in Obsolete: "


For Each objCurrent In objDicCurrent
        strCurrent = objDicCurrent.Item(objCurrent)
        objLogFile.WriteLine strCurrent
Next
objLogFile.WriteLine "Total no. of items in Current: " & intTotalItems


Set objDicCurrent = Nothing


intTotalItems = objDicObsolete.Count
objLogFile.WriteLine "----------------------"
objLogFile.WriteLine ""
objLogFile.WriteLine "Items in Obsolete but not in Current: "


For Each objObsolete In objDicObsolete
        strObsolete = objDicObsolete.Item(objObsolete)
        objLogFile.WriteLine strObsolete
Next
objLogFile.WriteLine "No. of items only in Obsolete: " & intTotalItems
objLogFile.WriteLine "----------------------"
Set objDicObsolete = Nothing
objLogFile.Close


Msgbox "Done"
Wscript.Quit

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

now the question remains the same....


Thanks
Ashok

(in reply to kirrilian)
 
 
Post #: 14
 
 RE: VBScript help - 12/7/2006 12:25:57 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Because I will wake up late tomorrow, I post this now. Comments & anwsers to questions
asap.


      

Log of my last Test:


      

(in reply to ashok_ganeshs)
 
 
Post #: 15
 
 RE: VBScript help - 12/7/2006 10:19:23 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
EDI files for EDI newbies like me:

After starting with
  http://en.wikipedia.org/wiki/Electronic_Data_Interchange
and
  http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=cbc31d70-9744-4687-a9db-8e86eb23bce6
this is my resume:

As this sample


      

shows, an EDI file consist of records separated by a RS (record separator). The sample uses
vbCrLf as RS, Ashok's files use ~. The first record is a special header. Records
consist of fields separated by a FS (field separator). The sample uses |, Ashok's files
use *. The first field of a record is a special tag, indicating something (or other) about
the other fields.

As EDI files are machine generated, I'm fairly confident that transformations (replacing
RS ~ with RS vbCrLf to ease a 'line by line' comparison etc) aren't too difficult.

In my opinion, the concept of "Link" is crucial to the project. A Link is some unique part
of the content of an EDI file A, that can be used to determine whether or not another EDI
file B should be compared to A.

If I understand Ashok's

    i need to find "TRN" String first then go to that line you can
    see three stars, the values are in between the stars right...so
    i need to pick the value in between second and third stars (i
    mean *BR05_FACILITY_Numeric*) based on that value do the search
    on the other folder files and compare the files

correctly "BR05_FACILITY_Numeric" (let's say from file A) is one instance of a Link. Given
this Link and some files B, C, ... an easy and efficient way to check file B would be to
use

   Instr( <ContentOfB>, <Link> )

or - more pedantic -

   Instr( 1, <ContentOfB>, <Link>, vbBinaryCompare )

But I'm afraid that could give false positives. (Think of spam detection: just looking
for 'dirty' words could classify a email from your doctor as spam.) That's why I used
the RegExp pattern

   "~TRN\*([^*]+)\*([^*]+)\*([^~]+)~"

in cutLink(). That way the context (tag TRN) and the field structure is taken into