Opinions anyone?

Results 1 to 5 of 5

Thread: Opinions anyone?

  1. #1
    Ian Stallings Guest

    Default Opinions anyone?

    I am developing a app that gets a recordset from a COM object<BR>and displays it on the screen in two columns <BR>(thanks to past help :)<BR><BR>So my question is this - which wahy is better:<BR>1. loop through all recordsets, place them in an array<BR>then display in two columns<BR><BR>2. loop using indexing and display directly into two columns<BR>like so:<BR><BR>for i = 0 to (count)<BR>object1 = object.data(i)<BR>response.write(object1)<BR><BR>o bject2 = object.data(i + count)<BR>response.write(object2)<BR>next<BR><BR>A s you can see, I have to get the data twice in the loop<BR>(actually it is allot more because it gets allot of data)<BR><BR>Does anyone think either way is quicker and why?<BR>

  2. #2
    John Weeflaar Guest

    Default RE: Opinions anyone?

    In my opinion, I prefer not to use arrays in this case as it&#039ll<BR>slow down a bit ( copying data costs time). You may notice the time difference when the number of objects increases.<BR>What you can do in my opinion, is to optimize the code by not<BR>using variables anymore. Instead, you can copy the data in the collection directly into the output argument (or wherever place needed).<BR>So, instead of:<BR><BR>object1 = object.data(i) &#039Here we assign data to object1 variable<BR>response.write(object1) &#039Then display it<BR><BR>You may want to write:<BR><BR>response.write(object.data(i)) &#039 copy data directly to output<BR><BR>In my previous example, it was just to make the code look simple.<BR>In practice, you don&#039t have to assign data into variables.<BR><BR>Regards,<BR><BR>John<BR>

  3. #3
    Bill Logan Guest

    Default RE: Opinions anyone?

    The way with the array is quicker it only has to be incremented to walk through the data. The recordset is more complex than that so it runs slower. That brings me to a problem that I had with this: no matter what cursor on the recordset I used, it wwould not give me thenumber of records found.

  4. #4
    John Weeflaar Guest

    Default RE: Opinions anyone?

    Answering your question first: You probably haven&#039t included<BR>adovbs.inc file to enable us to use ADO constants for record count.<BR><BR>Now, not to surprise anyone:<BR>A collection itself is an array! It is an array of objects.<BR>So, to access an object&#039s properties such as its name property, we only need to use a dot (.)<BR>eg:<BR>object.data(0).Name etc.<BR>So, there is no need to create another array and copying data from this array of objects (recordsets) to another array of objects (string objects for the name properties).<BR>We don&#039t even need to test which one is faster:<BR>Suppose there are 1000 objects in the collection.<BR>Using this array of objects (collection) we only need 500 loops<BR>to print names in 2 columns.<BR>If we use array&#039s copying way, we need:<BR>1000 loops to copy the recordset names to an array.<BR>Then, we still need another 500 loops to print the names in 2 columns from this array. So we end up with 1500 loops.<BR>So, using arrays of objects: 500 loops<BR> using copying data : 1500 loops (3 times)<BR><BR>Cheers,<BR><BR>John<BR><BR><BR><BR>< BR>

  5. #5
    Ian Stallings Guest

    Default RE: Opinions anyone?

    Good point John. It seems like storing the retrieved data<BR>in a variable is only more efficient if the data is usedmore than once. Since I&#039m looping through the collection<BR>this isn&#039t needed. Thanks for the insight!<BR><BR>Ian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts