aaargh!

Results 1 to 5 of 5

Thread: aaargh!

  1. #1
    Ian Stallings Guest

    Default aaargh!

    isn&#039t this ironic :)<BR><BR>I have came across somehting and I want to see erveyone thinks.<BR><BR>I am using a custom com object to return recordsets from a DB<BR>and I iterate through them like so: (this is just example)<BR><BR>for each objeCatalogCategory in objeCatalog.Categories(2,strID)<BR>strTemp = "&#060;tr>&#060;td>objeCatalogCategory.Name&#0 60;/td>&#060;tr>"<BR>next<BR><BR>Ok that works fine, so the problem is this-<BR>i need to write the results into TWO columns on the page<BR>and I can&#039t get more than one recordset at a time through the<BR>object. If anyone can help than I would appreciate it :)

  2. #2
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: aaargh!

    Hi Ian,<BR><BR>I figured that out, hope this is what you&#039re looking for:<BR><BR>No, you can&#039t get more that one object (recordset) at a time <BR>if you Use For Each.... <BR>But you can get as many objects as available<BR>In the collection at a time, if you use indexes. Here is an example:<BR><BR>Set obj = ObjectCatalog.Categories(2,strID)&#039 just to save writing<BR>&#039Now,get the count property of it (if there is no Count property,<BR>&#039you can use loop to get it):<BR>objcount = obj.Count &#039 Count property of the object<BR>&#039divide into 2 columns:<BR>numloops = objcount / 2 &#039Rounds down if objcount is an odd number<BR>For i = 0 To (numloops - 1)<BR> first = obj(i).Name<BR> second = obj(i + numloops).Name<BR> strTemp = "&#060;tr>&#060;td>first&#060;/td> &#060;td>second&#060;/td>&#060;/tr><BR> ...<BR>Next<BR>&#039 Now, if objcount is odd, we need to add the last data after that<BR>If IsOdd(objcount) Then &#039 I don&#039t know if this is a built in <BR> &#039function. If not, just create it.<BR> first = obj(objcount).Name<BR> strTemp = "&#060;tr>&#060;td>first&#060;/td>&#060;/tr>"<BR> ...<BR>End If<BR><BR>Cheers<BR><BR>John Weeflaar<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    1,315

    Default A little correction

    1. missing closing double quotes in strTemp.<BR>2.If IsOdd(objcount) Then <BR> first = obj(objcount - 1).Name &#039 I forgot the "-1"<BR> End If<BR><BR>John Weeflaar

  4. #4
    Ian Stallings Guest

    Default RE: A little correction

    Gracias John, you are the man. I ended up using this:<BR><BR>set obj = objeCatalog.Categories(2,strID)<BR>objCount = obj.Count<BR>numloops = objCount / 2<BR><BR>For i = 1 to (numloops) &#039 I had to start it at 1 or it wouldn&#039t &#039work<BR>varFirst = obj(i).name<BR>varSecond = obj(i + numloops).name<BR>strTemp = strTemp & "&#060;tr>&#060;td>" & varFirst & "&#060;/td>&#060;td>" & varSecond & "&#060;/td>&#060;/tr>"<BR>Next<BR><BR><BR>Thanks again! I love this message board :)<BR><BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: A little correction

    Hi Ian,<BR><BR>Glad it works. Just another note:<BR>Apparently:<BR> numloops = objcount / 2 rounds up ( when looping)<BR>I thought it rounded down (as int / int should round down). That&#039s what makes you have to start from 1. But it&#039ll mean you miss the 1st object to display(obj(0).Name), as indexing starts from 0 to (Count - 1).<BR><BR>So, you may want to use this function to make it to round down<BR>and looping can now start from i = 0 to (numloops - 1):<BR><BR>Function RoundDown(thevar)<BR> If (thevar mod 2) = 1 Then &#039 if thevar is odd<BR> RoundDown = thevar - 1<BR> Else<BR> RoundDown = thevar<BR> End If<BR>End Function<BR><BR>Then, you&#039ll use:<BR>numloops = RoundDown(objcount) / 2<BR>...<BR>for i = 0 To (numloops - 1)<BR>...<BR>next<BR><BR>Hopefully all objects are displayed now.<BR><BR>Cheers<BR><BR>John Weeflaar<BR><BR>

Posting Permissions

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