Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot check arrays for duplicates

Posted on 2004-08-09
6
Medium Priority
?
292 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

604 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