Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display RecordSet

Status
Not open for further replies.

lajchon

Programmer
Oct 14, 2004
4
US
I have code that dumps data from a database into a class with a public array called Record, ie

Ticket.Record(X).ID = "1"
Ticket.Record(X).Subject = "Subject"

In this example I have 8 records in the class of Ticket.Record. What I am wanting to do is display 5 records at a time and when I hit the Next button, display the next few records in the set. The problem I am running into the the code that knows to display the first 5 then the next 3 then back again. Or if there are multiple "pages" of records.

I've tried numerous approaches but have been unable to create anything solid. Any suggestions?
 
could you post your code for the class??

will you need a new property of the class?,,,something like

Ticket.CurrPosition
and perhaps
Ticket.NumRecords

'sorry the below addlib'ng

Sub Next_Click()
'display next set
'get start point
i = Ticket.CurrPosition
If i <> Ticket.NumRecords Then
If Ticket.numRecords - i >= 5 Then
For i To (i + 5)
Wscript.Echo Ticket.Record(i).Subject
Next
'set curr poss
Ticket.CurrPostion = Ticket.CurrPostion + 5
Else
'in the last segment
For i To (i + (Ticket.numRecords - 1) )
Wscript.Echo Ticket.Record(i).Subject
Next
'should reset to the end?
Ticket.CurrPos = Ticket.NumRecords
End If
Else
'should show first page
i = 0
For i To (i + 5)
Wscript.Echo Ticket.Record(i).Subject
Next
Ticket.CurrPostion = 5
End If
End Sub


 
Class TicketData
Public Record()
Public RecordCount

Sub Update
'Dumps data from database into Record(X)
Set Record(X) = New RecordData
Record(X).DBID = ResultSet.GetColumnValue(1)
Record(X).ID = ResultSet.GetColumnValue(2)
Record(X).Subject = ResultSet.GetColumnValue(3)
Record(X).State = ResultSet.GetColumnValue(4)
Record(X).DateScheduled = ResultSet.GetColumnValue(5)
Record(X).Queue = ResultSet.GetColumnValue(6)
Status = ResultSet.MoveNext
End Sub
End Class

Class RecordData
Public DBID
Public ID
Public Subject
Public State
Public DateScheduled
Public Queue
End Class

Thanks for the help!!
 
I'd be more curious what you mean by "display" pages of the Record() array and "Next" button.

For example, is this client-side paging in IE or are you talking about something like an ASP application and round-tripping to the server? The latter makes your "Next button" a sort of submit button, doesn't it?

Or is IE not involved here at all?

I hate tossing out full-code answers, but here's a quick-hack example of what I mean by client-side to save a lot of verbiage. Please ignore my dummied-up data, I'm just populating a Record() array with junk and then showing how you can page it.
Code:
<HTML>
<HEAD>
<TITLE>View Array in a Table, Paged</TITLE>
<SCRIPT language=vbscript>
Option Explicit

Class clsRecord
  Public ID
  Public Subject
End Class

Dim Record()
Const kPageSize = 5 'Lines per page to display.
Const kArrayLast = 27 'Last element in array (size - 1).
Dim lngCurrPage

Sub DisplayPage
  Dim lngRow, lngRecord

  For lngRow = 0 To kPageSize - 1
    lngRecord = kPageSize * lngCurrPage + lngRow
    If lngRecord <= kArrayLast Then
      colID(lngRow).innerText = Record(lngRecord).ID
      colSubject(lngRow).innerText = Record(lngRecord).Subject
    Else
      colID(lngRow).innerHTML = "&nbsp;"
      colSubject(lngRow).innerHTML = "&nbsp;"
    End If
  Next
End Sub

Sub btnFirst_onclick
  lngCurrPage = 0
  DisplayPage
End Sub

Sub btnBack_onclick
  Dim lngRow

  If lngCurrPage > 0 Then
    lngCurrPage = lngCurrPage - 1
    DisplayPage
  End If
End Sub

Sub btnNext_onclick
  If (lngCurrPage + 1) * kPageSize <= kArrayLast Then
    lngCurrPage = lngCurrPage + 1
    DisplayPage
  End If
End Sub

Sub btnLast_onclick
  lngCurrPage = kArrayLast \ kPageSize
  DisplayPage
End Sub

Sub window_onload
  Dim i, objRow, objCell, arySubjStuff

  For i = 1 To kPageSize
    Set objRow = tblDisplay.insertRow()
    Set objCell = objRow.insertCell()
    objCell.id = "colID"
    objCell.align = "right"
    objCell.innerHTML = "&nbsp;"
    Set objCell = objRow.insertCell()
    objCell.id = "colSubject"
    objCell.innerHTML = "&nbsp;"
  Next
  Set objCell = Nothing
  Set objRow = Nothing

  arySubjStuff = _
    Array("Two guys walking down a road", _
          "The last train home", _
          "One girl, one guy", _
          "Peanuts and a sultry afternoon", _
          "Vinyl records", _
          "Area 51", _
          "Hurricane Jeanne", _
          "My last dollar", _
          "52 pickup", _
          "George Washington", _
          "Pair of shoes on the telphone wire", _
          "Hot air balloons")
  Randomize
  ReDim Record(kArrayLast)
  For i = 0 To kArrayLast
    Set Record(i) = New clsRecord
    Record(i).ID = i
    Record(i).Subject = _
      arySubjStuff(Fix(Rnd * (UBound(arySubjStuff) + 1)))
  Next

  DisplayPage
End Sub
</SCRIPT>
</HEAD>
<BODY bgcolor=lightsteelblue>
<H1>View Array By Page</H1>
<INPUT type=button id=btnFirst value=" << ">
<INPUT type=button id=btnBack value=" < ">
<INPUT type=button id=btnNext value=" > ">
<INPUT type=button id=btnLast value=" >> ">
<TABLE id=tblDisplay border=1>
  <THEAD>
    <TR style="background-color: dimgray; color: white;
               font-weight: bold; text-align: center">
      <TD>ID</TD>
      <TD>Subject</TD>
    </TR>
  </THEAD>
</TABLE>
</BODY>
</HTML>
The onload event handler here just builds out the display table (you can hard-code this instead of doing it dynamically of course) and loads up the Record() array with a bunch of objects with dummy data. Just copy/paste it into an HTM file to test it.

If you do want client-side paging, how is the data getting to the client page? If you were using RDS or some other DSO you could just use IE data binding to such a display table. Of course then you wouldn't need this class and array at all.

Even if you want to round-trip for pages, this offers a crude model for paging through your data.


Or am I way off in left field, entirely missing the point of your question?
 
This is actually just a vbscript application for Windows. The data will be read into Ticket.Record(). If there is more than 5 records to display on one page then by clicking the "Next" button it will display the next set. If there are more than 5 on that page then "Next" will be available until all records are displayed. Then will travel back through recordset with a "Prev" button.

Just trying to figure out the logic of how to display the data and page through it. I know it's simplier than I think and I'm probably just overlooking something.

Thanks again.
 
Problem solved. Thanks again for the code examples :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top