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
       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

You might also like...

Comments

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.

Contribute

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.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra