| 416-621-9348 cgreaves@chrisgreaves.com | |
|---|---|
| Home Services Products |
A Means Of Implementing “Undo” On GUI Forms ; Legalities ; The GUI Form ; The Data Control Events ; The Preservation Structure ; Initializing The Form ; Recording A Change ; Undoing A Change ; Inhibiting Undo ; Running The Form
Undoing A Change
In a general sense, this is merely the reverse of preserving a change:
Function GUI_Undo() With typ(UBound(typ)) Me.cb1 = .blncb1 Me.cb2 = .blncb2 Me.ob1 = .blnob1 Me.ob2 = .blnob2 Me.ob3 = .blnob3 Me.tb1 = .strtb1 Me.tb2 = .strtb2 End With ReDim Preserve typ(UBound(typ) - 1) End Function
However we must consider several things:
We ought not to permit an “undo” operation if there are no changes to be undone
We want to inhibit preservation of changes when such changes are not a direct consequence of user action. Two examples are (a) initialization of the controls during the user form initialization and (b) re-initialization of user form controls during the edit-undo operation.
To this end we introduce a simple global Boolean switch to inhibit recording:
Dim blnInhibit As Boolean Function GUI_Preserve() If blnInhibit Then Else ReDim Preserve typ(UBound(typ) + 1) With typ(UBound(typ)) .blncb1 = Me.cb1 .blncb2 = Me.cb2 .blnob1 = Me.ob1 .blnob2 = Me.ob2 .blnob3 = Me.ob3 .strtb1 = Me.tb1 .strtb2 = Me.tb2 End With End If End Function
We set and unset the switch around user form initialization, and we set and unset the switch around the undo operation.
Private Sub UserForm_Initialize() blnInhibit = True ReDim typ(0) ''' In here set default values for the user form controls blnInhibit = False End Sub
Private Sub cmdUndo_Click() blnInhibit = True Call GUI_Undo blnInhibit = False End Sub
Loading
Toronto and Mississauga, Sunday, December 05, 2010 3:12 PM
Copyright © 1996-2010 Chris Greaves. All Rights Reserved.