Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 9th, 2008, 12:32 PM
Authorized User
Join Date: Jun 2008
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default How do i write code to go back or undo

I have an inspection station that an operator clicks buttons on the screen choosing pass or fail. AS they click the information is saved to a file. If they click the wrong button I want them to be able to go back and be able to select the right button. Is there a way to have a back button that simply undoes the last step of the program run or basically rewinds the program to the last user input of them clicking the button so as to have not clicked the button?

Old July 9th, 2008, 05:10 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

You have to write this behavior into the program yourself.

From what I see from your description, perhaps the thing for [u]you</u> to do (given that you write to a file) is to keep track of how many lines you have written to the file. If they click “Back” or “Undo,” create a new file, and write all of the lines of the current file into the new file--except the most recent. If you just wrote line 5, write 4 lines to the new file. If you just wrote line 28, write the 1st 27 lines of the current file to the new file.

Then close both files, delete the original, rename the new one, and open it as the currnet file. Then present the previous display to the user to allow them to make the right pick this time.

The thing for you to do will be dictated by what your program does, how it implements tha, and so on. But the bottom line is that you have to write “Undo” behavior yourself. (With a database you can make this easier with transactions, but you still have to write the code that uses transactions, and their ability to “Rollback” to the start of the transaction.)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help, what code should I write here? vincentleo ASP.NET 2.0 Basics 2 March 10th, 2008 10:09 AM
re write a code kgoldvas XSLT 3 August 1st, 2007 07:40 AM
how write vb code in c# ravpaw General .NET 2 July 1st, 2007 02:13 PM
How to Undo SHFileOperation action from VB code? vb_programmer Pro VB 6 0 July 15th, 2006 02:51 AM
My UNDO wont UNDO socoolbrewster Access 2 March 22nd, 2004 08:36 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.