Solved

Using Undo in a Text Editor

Posted on 1998-08-13
12
268 Views
Last Modified: 2010-04-30
Does anyone know a way to make the "Undo" command in a Text Editor work (the undo on the Project's tool bar). Now, I have tried saving a temp file and using a timer, etc..., but there must be a way to actually enable undo to do what it should (notice that in Microsoft's Wordpad, you can undo more than one change, so it's not just save a copy or make it a variable, etc... There has to be a way to make it be able to undo maybe 6 or 7 or all of the changes. That's what I need to know). Thanks for all the help you can give.
0
Comment
Question by:guinness
  • 3
  • 3
  • 2
  • +3
12 Comments
 

Expert Comment

by:hess
ID: 1468745
this will give you 30+ level undo on a text box and will takes a max of 1meg mor memory the numbers in the for next loops and the elements in the arry could be increased to allow for greater undoabiltiy. In txtmain_change() this line must be added

Call myundo(1)

and in your undo menu item add

call myundo(2)

Public Sub myundo(x As Integer)
Static undotxtMain(32) As String
If x = 1 Then
    For x = 31 To 0 Step -1
    undotxtMain(x + 1) = undotxtMain(x)
    Next x
    undotxtMain(0) = txtMain.Text
Else
    txtMain.Text = undotxtMain(1)
    For x = 1 To 32
        undotxtMain(x - 1) = undotxtMain(x)
    Next x
   
    For x = 1 To 32
        undotxtMain(x - 1) = undotxtMain(x)
    Next x
   
End If
End Sub
0
 
LVL 2

Expert Comment

by:rene100
ID: 1468746
hi guinnes

you must use the windows-api function 'SendMessage'
the first parameter is the handle of the texteditor, the
second EM_UNDO and both the following 0.
the only problem ist that you can't undo more than 1
change.

rene



0
 

Author Comment

by:guinness
ID: 1468747
I know you are going to cut me to shreads for doing this, but there is a problem in the code. I know, it may not be your fault, but it's gonna' kill me if I can't get this to work (I can create an Enterprise Solution but not a Text Editor). On the line after the "ELSE", I am getting Run-time Error '424', Object Expected and, since I didn't write the code, I can't figure out what it wants. Hess, if you hurry and re-answer I'll try and give you the points. Thanks.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 6

Expert Comment

by:anthonyc
ID: 1468748
dude,

use the sendmessage solution, it's much nicer.

sendmessage text1.hwnd, EM_UNDO, 0&, 0& 'look in the API viewer for the decls of sendmessage and em_undo
0
 
LVL 7

Expert Comment

by:kamall
ID: 1468749
guinness,
Certainly, your problem is that your text box has a name other than 'txtMain'.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1468750
anthonyc,
I wanted to answer the question before you, but I found it unfair to do that since hess's answer was a good one.

guinness,
If my previous comment solves your problem, please think of to whom you should award the points.

Regards to all.
0
 

Author Comment

by:guinness
ID: 1468751
I would like for Hess's answer to work, and, my Text Box name IS txtMain. I've already checked that.
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1468752
hah.. you'd rather go with the non-windows solution.... fine.
0
 

Author Comment

by:guinness
ID: 1468753
Hess: It looks as though the solution that was given earlier did NOT work. What it DID do was create a New Document named frmDocument (It opened frmDocument basically). Wanna try and fix it or should I go for another solution/
0
 

Accepted Solution

by:
hess earned 150 total points
ID: 1468754
if you make the object name match the real objects being used then there is no problem. txtMain.Text should be changed to the string that the undo will work on it can be any variable so if it was text1.text then change the cod to look like this:

 
Public Sub myundo(x As Integer)
       Static undotxtMain(32) As String
       If x = 1 Then
           For x = 31 To 0 Step -1
           undotxtMain(x + 1) = undotxtMain(x)
           Next x
           undotxtMain(0) = Text1.Text
       Else
           Text1.Text = undotxtMain(1)
           For x = 1 To 32
               undotxtMain(x - 1) = undotxtMain(x)
           Next x
           
           For x = 1 To 32
               undotxtMain(x - 1) = undotxtMain(x)
           Next x
           
       End If
       End Sub


the error 424 was created because the code refferd to an object that wasn't there so mak sure to make the 2 object references in the code point to real objects.
0
 

Expert Comment

by:hess
ID: 1468755
if your text box name is txtmain.text then i don't know what the problem is. I works on my computer.
0
 
LVL 3

Expert Comment

by:HATCHET
ID: 2181736
Quick comment... if you use the SendMessage API, you will NOT be able to undo any Cut/Copy/Paste/Delete functionality that you add to your project manually using say the .SelText or .Text properties.  For some reason, it doesn't acknowledge such "manual" edits as valid edits to undo.  If you type it, the SendMessage API will undo it... that's about the extent of it.  NO MULTI-LEVEL UNDO... that's why this code is more advantageous.

Windows isn't always righ!    ; P

HATCHET
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question