Re: Loop Problem (At Least I think)
From: Chris Guimbellot (cguimbellot_at_FORGETSPAM.hifranchise.com)
Date: 03/22/04
- Next message: hsjqueiroz: "Looking for wrong Gateway"
- Previous message: Torgeir Bakken \(MVP\): "Re: deleting registry keys based on value."
- In reply to: McKirahan: "Re: Loop Problem (At Least I think)"
- Next in thread: McKirahan: "Re: Loop Problem (At Least I think)"
- Reply: McKirahan: "Re: Loop Problem (At Least I think)"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Mar 2004 13:35:29 -0500
Thanks for the help. I used the code you gave me and have it working. I do
have a few questions though:
1. If there are no images (items in the dictionary) matching the product
code, then instead or showing zero between the parenthesis, it shows
nothing. Everything else about the output seems to be correct.
2. I tried to examine the code you gave me. I understand everything except
for the middle section you gave me including the "Do While...Loop" and the
"If...End If" statement right below it. Specifically, I guess what I am not
understanding is why the iCount variable isn't set until after the first
objDIC.Add line. It would seem to me that to add the item, you would have to
set iCount equal to something before you do. In regards to the "If strPRD <>
"" Then" statement (the one below the loop, outside of it), is this just
there to add the last element to the dictionary? I am kind of messed up when
looking at this code. I could really use some help interpreting it.
Once again, thanks for your help. I really appreciate it.
Chris
"McKirahan" <News@McKirahan.com> wrote in message
news:aFF7c.59122$_w.917947@attbi_s53...
> "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: hsjqueiroz: "Looking for wrong Gateway"
- Previous message: Torgeir Bakken \(MVP\): "Re: deleting registry keys based on value."
- In reply to: McKirahan: "Re: Loop Problem (At Least I think)"
- Next in thread: McKirahan: "Re: Loop Problem (At Least I think)"
- Reply: McKirahan: "Re: Loop Problem (At Least I think)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|