Solved

Cannot check arrays for duplicates

Posted on 2004-08-09
6
286 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now