Members
Technology Zones
Articles
Hosted By
Info
|
Rated
Read 10,229 times
Downloads
Related Categories
Multiple Undo for text boxes
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
Use this code how you want, but please do not distribute it
publically (eg. on the internet or in a book). If you use it for a
program, please email me a version, or a link to where I can obtain
one.
Happy programming!
James Williams - vb@jamwi
Comments
|
Search
Related Content
Code Samples
New Members
|