Solved

Cannot check arrays for duplicates

Posted on 2004-08-09
6
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Author Comment

by:legalsrl
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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.

771 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