Re: Loop Problem (At Least I think)
From: McKirahan (News_at_McKirahan.com)
Date: 03/22/04
- Next message: Joe Becher: "deleting registry keys based on value."
- Previous message: Michael Holzemer: "Re: adding new primary SMTP address"
- In reply to: Chris Guimbellot: "Loop Problem (At Least I think)"
- Next in thread: Chris Guimbellot: "Re: Loop Problem (At Least I think)"
- Reply: Chris Guimbellot: "Re: Loop Problem (At Least I think)"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Mar 2004 17:47:50 GMT
"Chris Guimbellot" <cguimbellot@FORGETSPAM.hifranchise.com> wrote in message
news:eLDgyCDEEHA.1604@TK2MSFTNGP11.phx.gbl...
> Hello,
>
> I have a folder that contains images of products (the product info is
> located in the database). The naming convention for the images files is
the
> product code and then the number; each product can have multiple images.
An
> examples of the names is something like this:
>
> DARHS1,jog
> DARHS2.jog
> DARHS3.jpg
> ...
>
> Anyway, I have written a script that iterates through the folder and
writes
> the name of each image to a file called imagenames.txt (one image name per
> line) that will serve as a temporary folder just lasting long enough for
the
> script to finish.
>
> Goal of the script is to output the number of images per product. That
said,
> the script performs the following steps:
> 1. Creates the imagenames.txt and places the names of all of the images in
> the folder in it.
> 2. Opens the database and gets the product code for each product.
> 3. For each product code, go through the imagenames.txt file and count the
> number of images whose first 5 letters are the same as the property code.
> 4.Write the results to another file.
>
> The problem that I am having is that when it spits out the results, the
> number never increments. It seems like when iterating through the
> imagenames.txt file, it is not locating any of the image names, so when I
> run the script from the command line, it spits out zeros for every entry.
I
> have included my scripts below so maybe someone can see what I am missing.
>
> Do While Not rstProp.EOF
>
> propCode = rstProp("HIPropCode")
> WScript.Echo propCode
> iCount = 0
> Do While ts.AtEndOfStream = False
> lineText = ts.ReadLine
> If Left(lineText,5) = propCode Then
> iCount = iCount + 1
> End If
> Loop
>
> WScript.Echo Left(lineText,5) & " (" & iCount & ")"
>
> 'move to the next record when done
> rstProp.MoveNext
>
> Loop
>
> I think one of the problems is that I am not resetting the ts back to the
> beginning of the file each time. I know I am not phrasing this question
very
> well. Sorry about that.
>
> Any ideas on what's going on here? Thanks,
>
> Chris
"Do While ts.AtEndOfStream = False" may not be right...
Also, you can only process "ts" once after you open it.
Rather than process the entire file for each product code, I'd suggest:
1) Read the file into dictionary object
Dim objDIC
objDIC = CreateObejct("Scritping.Dictionary")
Dim strPRD
strPRD = ""
...
Do While Not ts.AtEndOfStream
lineText = ts.ReadLine
If strPRD <> Left(lineText,5) Then
If strPRD <> "" Then
objDIC.Add strPRD, iCount
End If
iCount = 0
strPRD = Left(lineText,5)
End If
iCount = iCount + 1
Loop
If strPRD <> "" Then
objDIC.Add strPRD, iCount
End If
...
Set objDIC = Nothing
2) Read the database table and acess the dictionary object for the count
Do While Not rstProp.EOF
propCode = rstProp("HIPropCode")
WScript.Echo propCode & " (" & objDIC.Item(propCode) & ")"
rstProp.MoveNext
Loop
- Next message: Joe Becher: "deleting registry keys based on value."
- Previous message: Michael Holzemer: "Re: adding new primary SMTP address"
- In reply to: Chris Guimbellot: "Loop Problem (At Least I think)"
- Next in thread: Chris Guimbellot: "Re: Loop Problem (At Least I think)"
- Reply: Chris Guimbellot: "Re: Loop Problem (At Least I think)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|