Search code examples
asp-classicrecordset

RecordSet, Checking the Last Record


I am using the google chart framework based on a data in database...

I need to generate an output like:

([
  ['Year',  'ON',   'OFF',  'X1',   'X2'],
  ['Jan/12',    2,  5,      10,         9],
  ['Fev/12',    5,  10,     54,         10],
  ['Mar/12',    10, 36,     15,         10]
]);

Note that the last line do not have a comma. My code looks like:

([
  ['Year',  'ON',   'OF',   'X1',   'X1'],
    <%
        WHILE NOT DB.EOF
        ON= DB("ON")
        OFF= DB("OFF")
        X1= DB("X1")
        X2= DB("X2")
    %>
        ['<% Response.Write Month %>/<% Response.Write Year %>',    <% Response.Write ON %>, <% Response.Write OFF %>, <% Response.Write X1 %>, <% Response.Write X2 %>,
    <%
        DB.MOVENEXT
        WEND
    %>
]);

My question: How can I check when the loop come to the last line, instead of put the comma, put just nothing?

Thanks!


Solution

  • AnthonyWJones's answer seems ok for me, but you could also ask inside loop if after move next you're not at EOF then you write ","

    ([ 
        ['Year',  'ON',   'OFF',   'X1',   'X2']
        <% Do While Not DB.EOF %>
            [
             '<%= Month %>/<%= Year %>', 
             <%= DB("ON") %>, 
             <%= DB("OFF") %>, 
             <%= DB("X1") %>, 
             <%= DB("X2") %>
            ]
            <%
            DB.MoveNext
            %>
            <% If Not DB.EOF Then %>
                ,
            <% End If %>
        <% Loop %>
    ]); 
    

    ;-)