Library code snippets
Undo and Redo
By Nick Avery, published on 14 Jul 2001
Undo and Redo
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
Related articles
Related discussion
-
Run-time error '91'
by crazyidane (0 replies)
-
Problem handling Redirects with MSXML2.XMLHTTP
by brandoncampbell (2 replies)
-
vbinputbox pauses code while it waits on response. How can I reproduce that?
by brandoncampbell (1 replies)
-
Sending SMS in VB 6
by sirobnole (6 replies)
-
Comboxbox listindex in ActiveX Control
by brandoncampbell (1 replies)
First, could you please explain at the beginning of code samples exactly what needs to be added to the form before your code can be used (i.e the lstUndo and lstRedo list boxes) and I'm sorry but this code simply is not an undo/redo code. It simply deletes all the text in the box on an undo, then puts it bak in agen on a redo, regardless of what changed
This thread is for discussions of Undo and Redo.