?
Solved

Cannot check arrays for duplicates

Posted on 2004-08-09
6
Medium Priority
?
291 Views
Last Modified: 2008-03-10
Hi,

I have the following code that reads the elements from an Access Table into an array.

'       Dimension a new array to read in the data

      Dim TotPart(200)
      Dim TotQty(200),TotQTM(200),TotRequired(200)
      arrcnt=1
      

'       This section now queries the results in the OutVar Table

            set OutVarGet = Server.CreateObject("ADODB.Recordset")
            outvarrs = "SELECT * FROM OutVar"
            
            set OutVarGet = BOMDBConnection.execute(outvarrs)
            
            if not OutVarGet.EOF then
                  Response.Write("Analyse Data for : ")
                  while not OutVarGet.EOF
                        Response.Write(" Items Required    : " & OutVarGet("PartOut"))
                        ' Response.Write(" Quantity Required : " & OutVarGet("QtyOut") & "<BR>")
                        Response.Write(" Qty per           : " & OutVarGet("QtyTM") & "<BR>")
                        TotPart(arrcnt) = OutVarGet("PartOut")
                        TotQty(arrcnt) = OutVarGet.Fields("QtyOut")
                        TotQTM(arrcnt) = OutVarGet("QtyTM")
                        TotRequired(arrcnt) = CDbl(TotQty(arrcnt)) * CDbl(TotQTM(arrcnt))
                        Response.Write(" Overall Quantity Required : " & TotRequired(arrcnt) & "<BR>")
                        
                        arrcnt=arrcnt + 1
                        OutVarGet.movenext()
                  wend
                  else
            end if


What I want to do is to then check the arrays for duplicate parts numbers, if the part already exists in the array, then I need to add the TotRequired Field to the existing TotRequired amount i.e. generating a total quantity required for each individual part number

The above code outputs the following :

Items Required : SAS138114 Qty per : 50
Overall Quantity Required : 50
Items Required : SAS138201 Qty per : 50
Overall Quantity Required : 50
Items Required : SAS138212 Qty per : 50
Overall Quantity Required : 50
Items Required : SAS138227 Qty per : 50
Overall Quantity Required : 50
Part : FIP100055Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0Total Required for : is 0


Please help !!!

Thanks
Si
0
Comment
Question by:legalsrl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Clif
ID: 11751725
Basicall what you need to do is sort the array by part number (either through an ORDER BY on your query or by running the array through a sort routine.

Then create a variable called something like sOldPartNumber

Finally, as you go through your loop, test sOldPartNumber against the part number from the array.  If it matches, add as you said above.  Then (and this is important) assign sOldPartNumber to the current part number array element.

So your code might look something like this:

dim sOldPartNumber
dim TotQty(200)

          outvarrs = "SELECT * FROM OutVar ORDER BY PartOut"
         
          set OutVarGet = BOMDBConnection.execute(outvarrs)
         
          if not OutVarGet.EOF then
               Response.Write("Analyse Data for : ")
               while not OutVarGet.EOF
                    Response.Write(" Items Required    : " & OutVarGet("PartOut"))
                    ' Response.Write(" Quantity Required : " & OutVarGet("QtyOut") & "<BR>")
                    Response.Write(" Qty per           : " & OutVarGet("QtyTM") & "<BR>")
                    TotPart(arrcnt) = OutVarGet("PartOut")
                    TotQty(arrcnt) = OutVarGet.Fields("QtyOut")
                    TotQTM(arrcnt) = OutVarGet("QtyTM")
                    TotRequired(arrcnt) = CDbl(TotQty(arrcnt)) * CDbl(TotQTM(arrcnt))
                    Response.Write(" Overall Quantity Required : " & TotRequired(arrcnt) & "<BR>")
                   
If sOldPartNumber = OutVarGet("PartOut") Then
    TotQty(arrcnt) = TotQty(arrcnt) + TotRequired(arrcnt)
End If

sOldPartNumber = OutVarGet("PartOut")

                    arrcnt=arrcnt + 1
                    OutVarGet.movenext()
               wend
               else
          end if


0
 
LVL 16

Author Comment

by:legalsrl
ID: 11751998
Hi Cliff,

Thanks for the response

Once I have entered the code, I am getting seperate entries.

What I need to do is summarise the data, i.e. If I have two entries below :

Analyse Data for : 1382M
Analyse Data for : 1382M
Component Required : FIP100055 Quantity Required per unit : 1 Kit Qty to make : 25

Overall Quantity Required per line entry : 25
Component Required : FIP100055 Quantity Required per unit : 1 Kit Qty to make : 25

I need to just print 1 line saying

Component Required : FIP100055 Quantity Required :50

Thanks for your help though, it's much appreciated

Si
0
 
LVL 10

Expert Comment

by:Clif
ID: 11752129
Oops,

I see the problem.  You'll need a separate array count for the totals.


dim sOldPartNumber
dim TotQty(200)
dim nTotalCount
nTotalCount = 0
          outvarrs = "SELECT * FROM OutVar ORDER BY PartOut"
         
          set OutVarGet = BOMDBConnection.execute(outvarrs)
         
          if not OutVarGet.EOF then
               Response.Write("Analyse Data for : ")
               while not OutVarGet.EOF
                    Response.Write(" Items Required    : " & OutVarGet("PartOut"))
                    ' Response.Write(" Quantity Required : " & OutVarGet("QtyOut") & "<BR>")
                    Response.Write(" Qty per           : " & OutVarGet("QtyTM") & "<BR>")
                    TotPart(arrcnt) = OutVarGet("PartOut")
                    TotQty(arrcnt) = OutVarGet.Fields("QtyOut")
                    TotQTM(arrcnt) = OutVarGet("QtyTM")
                    TotRequired(arrcnt) = CDbl(TotQty(arrcnt)) * CDbl(TotQTM(arrcnt))
                    Response.Write(" Overall Quantity Required : " & TotRequired(arrcnt) & "<BR>")
                   
If sOldPartNumber = OutVarGet("PartOut") Then
    TotQty(nTotalCount) = TotQty(nTotalCount) + TotRequired(arrcnt)
Else
    nTotalCount = nTotalCount + 1
End If

sOldPartNumber = OutVarGet("PartOut")

                    arrcnt=arrcnt + 1
                    OutVarGet.movenext()
               wend
               else
          end if

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:legalsrl
ID: 11752274
Gotcha,

Once I have performed the above, surely I am going to need to apply the same type of thing outlined above on the new array set up for the totals ?

Si
0
 
LVL 10

Accepted Solution

by:
Clif earned 750 total points
ID: 11752528
I'm not sure what you mean by "apply the same type of thing"

But, thinking about it, what you probably have to do is set up a double array so that you can track which part number the total corresponds to.

Something like:

Dim TotQty(200,2)

Then, when you add values, you'd do:

If sOldPartNumber = OutVarGet("PartOut") Then
    TotQty(nTotalCount, 1) = OutVarGet("PartOut")
    TotQty(nTotalCount, 2) = TotQty(nTotalCount, 2) + TotRequired(arrcnt)
Else
    nTotalCount = nTotalCount + 1
End If

Finally, to print out the product number/totals:

For i = 0 to 200
    If TotQty(nCount, 1) <> ""
        Response.Write("Total for " & TotQty(nCount, 1) & " is " & TotQty(nCount, 2))
    End If
Next 'i
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 11752618
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question