Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (14 April 2014 - 05:28 PM) By The Way, This Could Be An Interesting Subject For A Topic, What About Posting This Question? Let's See If Other People Have The Same Feeling Concerning Bootlists!
@  yordan : (13 April 2014 - 09:36 AM) Boot Order : Cd, [Usb,] Hard Drive :D
@  yordan : (11 April 2014 - 07:23 PM) I Simply Let The Bios Do That
@  Ritesh : (11 April 2014 - 10:23 AM) Is It Possible To Launch Fedora Live Cd Or Installation Disk From Hard Drive On Windows Platform Using Grub Mbr File.
@  Ritesh : (11 April 2014 - 10:21 AM) No U Are Not.. Btw.. I Have Question For You.
@  yordan : (10 April 2014 - 08:02 AM) You Are Partially Right.
I Was Not.
Nevertheless, I Am Again :)
@  Ritesh : (09 April 2014 - 07:33 PM) :P
@  Ritesh : (09 April 2014 - 07:33 PM) I Think U R Not..
@  yordan : (09 April 2014 - 09:28 AM) I'm The Master Of The Shoutbox!
@  yordan : (05 April 2014 - 10:32 PM) He-He
@  Ritesh : (04 April 2014 - 06:59 PM) Ha Ha Ha ....
@  yordan : (04 April 2014 - 11:15 AM) Welcome Back, Starscream!
@  yordan : (03 April 2014 - 02:31 PM) And I Hope That He Will Come Back Soon :)
@  yordan : (01 April 2014 - 02:53 PM) Nice, Ritesh Came, I'm Not Home Alone Today.
@  Ritesh : (01 April 2014 - 08:51 AM) Oh!!! Poor Dear Yordan..
@  yordan : (31 March 2014 - 10:02 AM) I'm A Poor Lonesome Cow-Boy
@  yordan : (27 March 2014 - 02:22 PM) He Is Unpatient Due To His Patients!
@  Ritesh : (27 March 2014 - 10:46 AM) :(
@  Ritesh : (27 March 2014 - 10:46 AM) He Is Busy With His Patients.
@  yordan : (26 March 2014 - 08:12 PM) Ahsani, Where Are You?

Photo
- - - - -

Vb 'undo' Help


4 replies to this topic

#1 dwaldman

dwaldman

    Newbie [ Level 1 ]

  • Members
  • 1 posts

Posted 18 September 2008 - 03:42 PM

Not sure if this is the correct place to post this so I apologize in advance if it is not.

Before I post some code I was just wondering if someone could help me out. I have some VB code that goes inside an excel sheet that does a few things and it works correctly. The problem is that when you create something like this you lose the ability to use the default 'undo' excel has. From what I understand to make this work you need to create a 'undo' script for your function. Thats my problem, I have no clue how to create and undo script for my function. I got the code from a guy but am unable to get ahold of him for help on this.

Can someone in here help me create the undo function? I will post what I have if so...

#2 Jeigh

Jeigh

    Whitest Black Mage

  • Members
  • 1,381 posts
  • Gender:Male
  • Location:NB, Canada
  • Interests:My interests are my hobbies, and ironically enough my hobbies are my interests. I'm quite interested in my hobbies, much more so then my interests... but I spend more time with my interests as my hobbies are often rude with me so I don't enjoy talking to them as much.
  • myCENTs:93.97

Posted 18 September 2008 - 04:49 PM

I imagine an undo script would be doable if you simply had the code that alters a cell or cells in an excel sheet save a copy of those cells in a variable in memory prior to making the changes. This would allow for a review of the contents as altered by your new code and if they were incorrect a click of the undo button could over-write the new cell data with that stored in the variables of the original data. I'm not sure what scale or how precise you want the undo function but I'm sure you could change the granularity of such a procedure to whatever you need or want.

But yea, to summarize: Determine cell(s) to be affected, back them up in some way, over write the cells, review changes, continue as normal or replace with original data if required.

Hope this helps, if not maybe more information on your part could be useful.

#3 turbopowerdmaxsteel

turbopowerdmaxsteel

    Premium Member

  • [HOSTED]
  • 449 posts
  • Gender:Male
  • Location:Kolkata, India
  • Interests:Programming, Gaming, Cricket, Listening to Music and watching action cartoons.
  • myCENTs:30.99

Posted 19 September 2008 - 07:04 AM

The basis of creating an undo mechanism is the set of data structures you use. You will have to use a stack (two if you want to allow redo operations too). You will need to create a class which will store the address of the cell (Row, Column) and the value of the cell, before the change occured. C# code for the same is given below.

Class Action
{
	int Row, Column;
	object Value;
}

The stack should be of this type:-

Stack<Action> UndoHistory, RedoHistory;

Now, whenever you are about to change a value, create an instance of the Action class storing the details of the cell, i.e. its location and current value. Then, proceed with the change of value. You can enable/disabled the undo button by checking the length of the UndoHistory stack (disabled if its size is 0). Same goes for RedoHistory.

When you do an undo operation, an item from the UndoHistory stack should be popped. The Current value and location of the cell should be stored in a new instance of the Action class. This should be added to the RedoHistory stack.

While doing a redo, you must do the reverse. Push the current value & location to the UndoHistory. Pop an item from the RedoHistory and change the current value to match it.

This is a simple implementation. Your Action class can be much more complex. It might take into consideration multiple cells being changed by one operation, etc. But, the base mechanism would be similar.

#4 Darasen

Darasen

    Premium Member

  • [HOSTED]
  • 215 posts
  • Gender:Male
  • Location:Milling about
  • myCENTs:68.76

Posted 20 September 2008 - 02:52 AM

Making an undo function in VBA is certainly do-able.
For starters in you OP you state VB I am assuming that you actually intended to say VBA.
A quick search for "VBA Undo" gave me several results. A quick look at the code here seemed to fit the bill. Microsoft's website has some information as well though it seems to be geared to the latest version of Office. The specific example is in Project though I do believe the code would be interchangeable to Excel. The MSDN website often has very helpful information for VBA programming.

Best of luck.

#5 Guest_(G)Dilip_*

Guest_(G)Dilip_*
  • Guests

Posted 18 April 2009 - 01:02 PM

How to implement UNDO and REDO operations in vb.netVb 'undo' Help

How to implement UNDO and REDO operations in vb.Net windows application.. 

-reply by Dilip

 





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users