Use AddUndo to start adding pauses in-between when the user is typing. One way to do this is to use this code.
Private Sub Text1_Change()
Timer1.Interval = 5000
End Sub
Private Sub Timer1_Timer()
Undo1.AddUndo Text1.Text
Timer1.Interval = 0
End Sub
When you want to undo use Undo and Redo to redo.
Dim OldContent As String
Dim Last As UndoDirection
Public Enum UndoDirection
DirUndo = 1
DirRedo = 2
End Enum
Public Function Undo()
Dim Front As Double
Dim Back As Double
Dim StrFront As String
Dim StrBack As String
Dim Changed As String
If Last = DirRedo Or Last = 0 Then
Last = DirUndo
Undo
End If
Last = DirUndo
If lstUndo.ListCount = 0 Then
Undo = OldContent
Exit Function
End If
lstUndo.Selected(lstUndo.ListCount - 1) = True
Undo = lstUndo.Text
OldContent = Undo
lstRedo.AddItem lstUndo.Text
lstUndo.RemoveItem lstUndo.ListCount - 1
End Function
Public Function Redo()
If Last = DirUndo Or Last = 0 Then
Last = DirRedo
Redo
End If
Last = DirRedo
If lstRedo.ListCount = 0 Then
Redo = OldContent
Exit Function
End If
lstRedo.Selected(lstRedo.ListCount - 1) = True
Redo = lstRedo.Text
OldContent = Redo
lstUndo.AddItem lstRedo.Text
lstRedo.RemoveItem lstRedo.ListCount - 1
End Function
Public Sub AddUndo(NewContent As String)
Dim Content As String
Dim XStr As String
Content = NewContent
If OldContent = Content Then Exit Sub
lstRedo.Clear
lstUndo.AddItem Content
OldContent = NewContent
End Sub
Comments