Link to home
Start Free TrialLog in
Avatar of Simon Earl
Simon EarlFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Cannot check arrays for duplicates

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
Avatar of Clif
Clif
Flag of United States of America image

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


Avatar of Simon Earl

ASKER

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

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
ASKER CERTIFIED SOLUTION
Avatar of Clif
Clif
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial