Attribute VB_Name = "clsWizard"
Option Compare Database Option Explicit 'Модуль класса для создания "многостраничных" форм, таких как стандартные "мастера" в MS ACCESS. 'author: Олег Сморчков aka osmor 'E-mail:( osmor@mail.ru Этот e-mail защищен от спам-ботов. Для его просмотра в вашем браузере должна быть включена поддержка Java-script ) 'WWW: http://www.HiProg.com 'date: 08.11.2006
Public m_intCurrentPage As Integer ' текущая страница Private m_strPrefSubfrm As String ' префикс форм Private m_intNumLastPage As Integer ' номер последней страницы Private WithEvents m_cmdPrev As CommandButton ' кнопка назад Private WithEvents m_cmdNext As CommandButton ' кнопка вперед Private WithEvents m_cmdFinish As CommandButton ' кнопка готово Private m_ctlSubfrm As SubForm 'сабформа в которой будут отображаться страницы Private Sub Class_Initialize() m_intCurrentPage = 1 m_intNumLastPage = 1 End Sub Private Sub Class_Terminate() Set m_cmdPrev = Nothing Set m_cmdNext = Nothing Set m_cmdFinish = Nothing Set m_ctlSubfrm = Nothing End Sub '*********************************************************** 'comment: Процедура установки первой страницы визарда 'и начальной доступности кнопок '************************************************************ Public Sub startwiz()
On Error GoTo Err_startwiz ChangePage 0 'вызываем смену страниц
Exit_startwiz: Exit Sub Err_startwiz: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре startwiz " Resume Exit_startwiz End Select End Sub '*********************************************************** 'comment: процедура управления доступностью кнопок '************************************************************ Private Sub EnableButton() On Error GoTo Err_EnableButton Select Case m_intCurrentPage Case 1 ' первая страница m_cmdNext.Enabled = True m_cmdNext.SetFocus m_cmdPrev.Enabled = False m_cmdFinish.Enabled = False Case m_intNumLastPage ' последняя страница m_cmdFinish.Enabled = True m_cmdPrev.Enabled = True m_cmdFinish.SetFocus m_cmdNext.Enabled = False Case Else ' все другие страницы m_cmdPrev.Enabled = True m_cmdNext.Enabled = True m_cmdNext.SetFocus m_cmdFinish.Enabled = False End Select Exit_EnableButton: Exit Sub Err_EnableButton: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре EnableButton " Resume Exit_EnableButton End Select End Sub '*********************************************************** 'comment: свойство префикс для сабформ '************************************************************ Public Property Let PrefSubfrm(ByVal strPrefSubfrm As String)
On Error GoTo Err_PrefSubfrm
m_strPrefSubfrm = strPrefSubfrm
Exit_PrefSubfrm: Exit Property Err_PrefSubfrm: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре PrefSubfrm " Resume Exit_PrefSubfrm End Select End Property '*********************************************************** 'comment: свойство последняя страница по нему определяется что надо активировать кнопку ' "Готово" '************************************************************ Public Property Get NumLastPage() As Integer
On Error GoTo Err_NumLastPage
NumLastPage = m_intNumLastPage
Exit_NumLastPage: Exit Property Err_NumLastPage: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре NumLastPage " Resume Exit_NumLastPage End Select End Property
Public Property Let NumLastPage(ByVal intNumLastPage As Integer)
On Error GoTo Err_NumLastPage m_intNumLastPage = intNumLastPage Exit_NumLastPage: Exit Property Err_NumLastPage: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре NumLastPage " Resume Exit_NumLastPage End Select End Property '*********************************************************** 'comment: кнопка "назад" '************************************************************ Public Property Set cmdPrev(ctlcmdPrev As CommandButton)
On Error GoTo Err_cmdPrev Set m_cmdPrev = ctlcmdPrev m_cmdPrev.OnClick = "[Event Procedure]"
Exit_cmdPrev: Exit Property Err_cmdPrev: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре cmdPrev " Resume Exit_cmdPrev End Select End Property '*********************************************************** 'comment: кнопка "вперед" '************************************************************ Public Property Set cmdNext(ctlcmdNext As CommandButton)
On Error GoTo Err_cmdNext
Set m_cmdNext = ctlcmdNext m_cmdNext.OnClick = "[Event Procedure]"
Exit_cmdNext: Exit Property Err_cmdNext: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре cmdNext " Resume Exit_cmdNext End Select End Property '*********************************************************** 'comment: кнопка финиш '************************************************************ Public Property Set cmdFinish(ctlcmdFinish As CommandButton)
On Error GoTo Err_cmdFinish
Set m_cmdFinish = ctlcmdFinish m_cmdFinish.OnClick = "[Event Procedure]"
Exit_cmdFinish: Exit Property Err_cmdFinish: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре cmdFinish " Resume Exit_cmdFinish End Select End Property '*********************************************************** 'comment: подформа в которой будут отображаться страницы. '************************************************************ Public Property Set Subfrm(ctlSubfrm As SubForm)
On Error GoTo Err_Subfrm
Set m_ctlSubfrm = ctlSubfrm
Exit_Subfrm: Exit Property Err_Subfrm: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре Subfrm " Resume Exit_Subfrm End Select End Property '*********************************************************** 'comment: процедура обработки для события нажатие кнопки "Далее" '************************************************************ Private Sub m_cmdNext_Click()
On Error GoTo Err_m_cmdNext_Click
ChangePage 1 ' вызываем смену страницы
Exit_m_cmdNext_Click: Exit Sub Err_m_cmdNext_Click: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре m_cmdNext_Click " Resume Exit_m_cmdNext_Click End Select End Sub '*********************************************************** 'comment: процедура обработки для события нажатие кнопки "Назад" '************************************************************ Private Sub m_cmdPrev_Click()
On Error GoTo Err_m_cmdPrev_Click
ChangePage -1 ' вызываем смену страницы
Exit_m_cmdPrev_Click: Exit Sub Err_m_cmdPrev_Click: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре m_cmdPrev_Click " Resume Exit_m_cmdPrev_Click End Select End Sub '*********************************************************** 'comment: процедура обработки для события нажатие кнопки "Готово" '************************************************************ Private Sub m_cmdFinish_Click()
On Error GoTo Err_m_cmdFinish_Click ' здесь можно вставить свой код для обработки нажатия кнопки "готово" MsgBox "Нажата кнопка " & Chr(34) & "Готово" & Chr(34)
Exit_m_cmdFinish_Click: Exit Sub Err_m_cmdFinish_Click: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре m_cmdFinish_Click " Resume Exit_m_cmdFinish_Click End Select End Sub '*********************************************************** 'author: osmor 'date: 08.11.2006 'comment: процедура изменения страницы '************************************************************ Private Sub ChangePage(intI As Integer)
On Error GoTo Err_ChangePage m_intCurrentPage = m_intCurrentPage + intI If m_intCurrentPage = 0 Then m_intCurrentPage = 1 If m_intCurrentPage > m_intNumLastPage Then m_intCurrentPage = m_intNumLastPage Call EnableButton m_ctlSubfrm.SourceObject = m_strPrefSubfrm & CStr(m_intCurrentPage)
Exit_ChangePage: Exit Sub Err_ChangePage: Select Case Err.Number Case Else MsgBox "(" & Err.Number & ") " & Err.Description & " в процедуре ChangePage " Resume Exit_ChangePage End Select End Sub |