Undo and Redo

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
   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
   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
   lstUndo.AddItem Content
   OldContent = NewContent
End Sub

You might also like...


Nick Avery I am as a web developer for a small company, working for a small company. I work on banking websites and verious related projects.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou