Library code snippets
Multiple Undo for text boxes
By James Williams, published on 06 Mar 2002
This is code for undo-ing the last action in a normal text box, with multiple undoes. There is also a redo function, but this doesnt work very well.
'this undo thing works very well with normal text boxes. even records things like delete, return or paste
'the redo thing doesnt work very well, but the undo is perfect
Dim redopressed As Boolean
Dim undopressed As Boolean
'change the bracketed number lower to use less system resources. the current is fine, but add another 0 and it can be slow. on slow pc's, make it lower.
'the no. in brackets is effectively the amount of changes remembered. the first change is no 1, so once youve got past the set number, undo will not work at all.
'e.g try setting it to 5
Dim str(1000000) As String
Dim bytChange As Double 'this was byte, but it only stored up to 255 changes, so i made it much bigger with double!
Private Sub cmdRedo_Click()
If redopressed = False Then
redopressed = True
If bytChange >= 0 Then _
Text1.Text = str((bytChange + 1))
If bytChange >= 0 Then bytChange = bytChange + 1
cmdRedo_Click
End If
If redopressed = True Then
redopressed = False
If bytChange >= 0 Then _
Text1.Text = str((bytChange + 1))
If bytChange >= 0 Then bytChange = bytChange + 1
End If
End Sub
Private Sub cmdUndo_Click()
If bytChange = 0 Then cmdUndo.Enabled = False
If undopressed = False Then
undopressed = True
If bytChange > 0 Then _
Text1.Text = str((bytChange - 1))
If bytChange >= 1 Then bytChange = bytChange - 1
cmdUndo_Click 'dont ask why this has to be done twice. i have no idea, but, hey, it works :)
End If
If undopressed = True Then
undopressed = False
If bytChange > 0 Then _
Text1.Text = str((bytChange - 1))
If bytChange >= 1 Then bytChange = bytChange - 1
cmdRedo.Enabled = True
End If
End Sub
Private Sub Form_Load()
bytChange = 1
undopressed = False
redopressed = False
End Sub
Private Sub Text1_Change()
cmdUndo.Enabled = True
If bytChange > 0 Then
str((bytChange + 1)) = Text1.Text
bytChange = bytChange + 1
End If
'Select Case bytChange | 'This is what the whole code
'Case 0: | 'does really. it remembers
'str(1) = Text1.Text | 'what the text was like each
'bytChange = 1 | 'time, and when undo is pressed,
'Case 1: <---| 'it works out when it is being
'str(2) = Text1.Text | 'pressed (bytchange), and
'bytChange = 2 | 'brings back what it was then.
'Case 2:
'str(3) = Text1.Text
'bytChange = 3
'End Select
End Sub
Related articles
Related discussion
-
Visual Studio: MDI Parent Form designer
by cutiegigshorty (0 replies)
-
Working on Who Wants To Be A Millionaire Project in VB6 [NEED HELP]
by candienne092 (2 replies)
-
Needs help with MSFlexGrid and MSAccess in VB6
by ClarkKentNeedsHelp (0 replies)
-
Make me or point me to an installer with comctl32 vb6
by tgkprog2 (0 replies)
-
How to use VB6 to make cumulative frequency polygons
by heibaidoufu (0 replies)
This thread is for discussions of Multiple Undo for text boxes.