Login | |
|
 |
RE: VBScript help - 12/13/2006 7:40:53 AM
|
|
 |
|
| |
ehvbs
Posts: 2077
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
Got my first rabbit punch after being so glad: EdiComp-04.vbs should generate reports like this # Processing all files in Folder .\FolderA ============================================================================== = File test1.edi contains Link BR01_FACILITY_Numeric = File test2.edi contains Link BR05_FACILITY_Numeric = File test3.edi contains Link BR-A-3_FACILITY_Numeric ============================================================================== = 3 files processed, 3 Links found. with code like this: reportStr "# Processing all files in Folder " + gsFolderA + vbCrLf + String( cnLiLen, "=" ) a For Each oFile In oFS.GetFolder( gsFolderA ).Files ... Next sRpt = "= @Files@ files processed, @Links@ Links found." b sRpt = Replace( sRpt, "@Files@", CStr( oFS.GetFolder( gsFolderA ).Files.Count ) ) sRpt = Replace( sRpt, "@Links@", CStr( dicLink.Count ) ) reportStr String( cnLiLen, "=" ) + vbCrLf + sRpt + vbCrLf + String( cnLiLen, "#" ) but Ashok just sent me a report like this: # Processing all files in Folder .\FolderA ============================================================================== = File test1.edi contains Link BR01_FACILITY_Numeric = File test2.edi contains Link BR05_FACILITY_Numeric = File test3.edi contains Link BR-A-3_FACILITY_Numeric ============================================================================== = 4 files processed, 3 Links found. Don't access volatile data more than once. The oFS.GetFolder( gsFolderA ) in line a may well be different from the oFS.GetFolder( gsFolderA ) in line b. The Count property may reflect files added (or deleted) between a and b. Another bad example is using Now more than once, for example to build a file name sFName = .. Year( Now ) ... Month( Now ) ... And guess what: some times ago I chided someone for that. The code (not tested) should be: reportStr "# Processing all files in Folder " + gsFolderA + vbCrLf + String( cnLiLen, "=" ) Dim oFiles : Set oFiles = oFS.GetFolder( gsFolderA ).Files ' one and only access a For Each oFile In oFiles ... Next sRpt = "= @Files@ files processed, @Links@ Links found." b sRpt = Replace( sRpt, "@Files@", CStr( oFiles.Count ) )
< Message edited by ehvbs -- 12/13/2006 7:41:59 AM >
|
|
| |
|
|
|
|
|