Private CN As ADODB.Connection Private RS As ADODB.Recordset Private PageCount As Long '总页数
程序代码:
Private Sub Build_Results(Optional Start_From = 0) On Error GoTo Err_1 Dim LI As ListItem ' ListItem object Dim Temp_Counter As Long Dim Last_Page As Long ' 当前记录集的最后一页 Dim Start_Page As Long '当前记录集的第一页 Dim X As Long LV_Results.ListItems.Clear Temp_Counter = 0 With RS If .RecordCount > 0 Then .Move Start_From * 13, 1 End If Do While Not .EOF And Temp_Counter < 13 ' DoEvents Set LI = LV_Results.ListItems.Add(, "K" & !Cur_ID, !Cur_Name) LI.SubItems(1) = !Country_Name LI.SubItems(2) = IIf(IsNull(!Alpha2_Code) = True, " ", !Alpha2_Code) LI.SubItems(3) = IIf(IsNull(!Currency_CodeA) = True, " ", !Currency_CodeA) LI.SubItems(4) = IIf(IsNull(!Currency_CodeN) = True, " ", !Currency_CodeN) .MoveNext Temp_Counter = Temp_Counter + 1 Loop T_Results.Caption = CStr(.RecordCount) ' 计算显示的记录数 If .RecordCount > 0 Then T_Showing_Records.Caption = (Start_From * 13) + 1 & " - " If (Start_From * 13) + 1 + 13 >= .RecordCount Then T_Showing_Records.Caption = T_Showing_Records.Caption & .RecordCount Else T_Showing_Records.Caption = T_Showing_Records.Caption & (Start_From * 13) + 13 End If Else T_Showing_Records.Caption = "0" End If ' 删除原来的记录导航显示 For T = 1 To T_Page.Count - 1 Unload T_Page(T) Next ' 获得最后一页 If .RecordCount Mod 13 > 0 Then Last_Page = Int(.RecordCount / 13) + 1 Else Last_Page = Int(.RecordCount / 13) End If PageCount = Last_Page '保存总页数,尾页需要使用 '获得要显示的第一页记录 For y = 1 To Last_Page Step 10 If Start_From + 1 >= y And Start_From + 1 <= y + 9 Then Exit For End If Next Start_Page = y X = 1 ' If we are showing pages not from first 20... <<- [ Previous ] If y > 1 Then '加载首页,并放到 <<- 之前 Load T_Page(T_Page.Count) T_Page(T_Page.Count - 1).Caption = "首页" T_Page(T_Page.Count - 1).Left = T_Page(T_Page.Count - 2).Left + T_Page(T_Page.Count - 2).Width + 90 T_Page(T_Page.Count - 1).Top = T_Page(T_Page.Count - 2).Top T_Page(T_Page.Count - 1).Visible = True Load T_Page(T_Page.Count) T_Page(T_Page.Count - 1).Caption = "<<-" T_Page(T_Page.Count - 1).Left = T_Page(T_Page.Count - 2).Left + T_Page(T_Page.Count - 2).Width + 90 T_Page(T_Page.Count - 1).Top = T_Page(T_Page.Count - 2).Top T_Page(T_Page.Count - 1).Visible = True End If For T = Start_Page To Last_Page Load T_Page(T_Page.Count) If X > 10 Then ' If there are more pages then we can show... ->> [ Next ] T_Page(T_Page.Count - 1).Caption = "->>" T_Page(T_Page.Count - 1).Left = T_Page(T_Page.Count - 2).Left + T_Page(T_Page.Count - 2).Width + 90 T_Page(T_Page.Count - 1).Top = T_Page(T_Page.Count - 2).Top T_Page(T_Page.Count - 1).Visible = True '加载尾页,并放到 ->> 之后 Load T_Page(T_Page.Count) T_Page(T_Page.Count - 1).Caption = "尾页" T_Page(T_Page.Count - 1).Left = T_Page(T_Page.Count - 2).Left + T_Page(T_Page.Count - 2).Width + 90 T_Page(T_Page.Count - 1).Top = T_Page(T_Page.Count - 2).Top T_Page(T_Page.Count - 1).Visible = True Exit For Else T_Page(T_Page.Count - 1).Caption = CStr(T) T_Page(T_Page.Count - 1).Left = T_Page(T_Page.Count - 2).Left + T_Page(T_Page.Count - 2).Width + 90 T_Page(T_Page.Count - 1).Top = T_Page(T_Page.Count - 2).Top If T = Start_From + 1 Then ' If this is a current page T_Page(T_Page.Count - 1).ForeColor = &HFF& End If T_Page(T_Page.Count - 1).Visible = True End If X = X + 1 Next End With Exit_Sub: Exit Sub Err_1: MsgBox Err.Description, vbOKOnly + vbCritical + vbApplicationModal, "StaCS : System error # " & Err.Number Resume Exit_Sub End Sub Private Sub T_Page_Click(Index As Integer) On Error GoTo Err_1 Me.AutoRedraw = False 'AutoRedraw 就是控制是否自动重绘的属性 Select Case T_Page(Index).Caption Case "->>" Call Build_Results(Val(T_Page(Index - 1).Caption)) Case "<<-" Call Build_Results(Val(T_Page(Index + 1).Caption) - 2) Case "首页" Call Build_Results(0) Case "尾页" Call Build_Results(PageCount - 1) Case Else Call Build_Results(Val(T_Page(Index).Caption) - 1) End Select ' 都是对一个值进行判断,改用多分支选择。原代码注释掉 ' If T_Page(Index).Caption = "->>" Then '自动生成的页码 ' Call Build_Results(Val(T_Page(Index - 1).Caption)) ' ElseIf T_Page(Index).Caption = "<<-" Then ' Call Build_Results(Val(T_Page(Index + 1).Caption) - 2) ' Else ' Call Build_Results(Val(T_Page(Index).Caption) - 1) ' End If Me.AutoRedraw = True Exit_Sub: Exit Sub Err_1: Resume Exit_Sub End Sub