Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Undo in a Text Editor

Posted on 1998-08-13
12
Medium Priority
?
274 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

916 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