Solved

Another VBScript/ASP problem

Posted on 2004-08-03
8
275 Views
Last Modified: 2008-02-01
Hi, I can't figure this out for the life of me, and I was wondering of anyone can help. I've got 2 functions; 1 to get a list of all orders for a certain part number, and the second to add the sum of the quantities of all orders on a certain day. Here is the code:

function GetShipmentsIn()
      dim shipIn
      redim shipIn(-1,1)
      set hubRS = createobject("adodb.recordset")
      hubRS.Open "SELECT dueDate, qty FROM ShipmentsIn WHERE partid="&partid&" AND BookedIn='NO'", hubcon
      do while not hubRS.EOF
            size = ubound(shipIn)
            if size = -1 then
                  redim shipIn(size+1, 1)
            else
                  redim preserve shipIn(size+1, 1)
            end if
            shipIn(ubound(shipIn), 0) = hubRS(0)
            shipIn(ubound(shipIn), 1) = hubRS(1)
            'Response.Write(shipIn(ubound(shipIn), 0))
            hubRS.MoveNext
      loop
      set hubRS = nothing
      GetShipmentsIn = shipIn
end function

function GetTodaysShipmentsIn(theDate)
      theDate = ReverseDate(theDate)
      count = 0
      for i=0 to ubound(shipments_in)
            if shipments_in(ubound(shipments_in), 0) = theDate then
                  Response.Write("adding: "&shipments_in(ubound(shipments_in), 1)&"<br />")
                  count = count + shipments_in(ubound(shipments_in), 1)
            end if
      next
      GetTodaysShipmentsIn = count
end function

Now, this works fine (i think) when the methods are ran just the once i.e., 'arr = GetShipmentsIn()' followed by 'tot = GetTodaysShipmentsIn(now)', but what I ideally want is to put the call to the second function in a for loop, which will calculate the sum of all the orders for each day of the week. When I put this call in a for loop, the browser times out. I could understand it if it was working with masses of data, but there are only 2 records in the database so it can't be pure worload that's timing-out the brower, can it?
Any suggestions welcome,
Cheers!
Darren.
0
Comment
Question by:led_zephrylin
[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
  • 3
  • 2
8 Comments
 
LVL 3

Expert Comment

by:dwaldner
ID: 11705885
I noticed that you didn't close HubRS...whenever I forget to close my recordset, it ALWAYS takes forever to execute....

Before your line:

set hubRS = nothing


Type this in

hubRS.Close

Cheers,

D
0
 
LVL 58

Expert Comment

by:Gary
ID: 11705905
Your first function could just become this

function GetShipmentsIn()
     set hubRS = createobject("adodb.recordset")
     hubRS.Open "SELECT dueDate, qty FROM ShipmentsIn ....
     GetShipmentsIn=hubRS.GetRows
     hubRS.Close
     set hubRS = nothing
end function

Then your shipin array contains all the data, much faster and cleaner.
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 11705910
Shouldn't you be passing the array to GetTodaysShipmentsIn()?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Expert Comment

by:dwaldner
ID: 11705912
Also, if I might make a recommendation...instead of rediming to get the size of the array, just use the hubRS.RecordCount to get the size of the recordset, then declare your array based on that size....just an idea to speed up that code...
0
 
LVL 58

Expert Comment

by:Gary
ID: 11705920
... that should be...
GetShipmentsIn array contains all the records
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 50 total points
ID: 11706408
Also rather than running thru the recordset you could just do
select sum(fieldname) from tablename ...
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 11706747
@dwaldner
I was thinking that too but RecordCount isn't available some (forward only) cursors.
0
 
LVL 3

Accepted Solution

by:
dwaldner earned 50 total points
ID: 11706770
Then do this:

hubRS.Open "SELECT dueDate, qty FROM ShipmentsIn WHERE partid="&partid&" AND BookedIn='NO'", hubcon, 3, 3

That will change your pointer to the appropriate type to accomplish this...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP SQL Syntax Duplicate Key 7 117
Hide cell in a table 2 33
Ajax on ASP 2 43
SQL Query Returns Records in SSMS but not Classic ASP 5 26
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…
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/…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

697 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