Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials 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, 2009, 11:03 AM
Authorized User
 
Join Date: Jun 2008
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Default Auto Save

I have a program that I have continually running and I want to be able to have it so if the the power goes out or the program closes all values from textboxes, variables, properties ect. can be restored to right where they were when the power was lost.

I thought about using a timer that gathers all values every minute or so and writes a text file but am unsure how to get all variables and property values.

I also would like it so when the computer restarts, the program restarts also, right where it left off by pulling all the information in from the text file or how ever it was saved.

Any ideas from you would be great.

Thanks
 
Old July 10th, 2009, 08:08 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Well you've stumbled on a situation where you have and plethora of answers, i can just list a few:
- Application Settings
- Stream reader writer
- FileOpen, FileClose, Put, Get excetera
Well thats for the saving the files.
The simplest way is the Application settings. To do this go to the My Project tree node in solution explorer.
Double click it and a new tab shall open up, now inside this are loads of tabs on there side going down the left hand side of the page, now click on the one that says settings.
Click in the highlighted first item in the listview (i think it says setting to begin with) and write in that what name you want to give the setting,
then the next column along defines what type of variable,
leave the scope as application,
and also leave the value blank aswell.

Now you can use this code:
Code:
Public Sub SaveSettings()
       My.Settings.[SettingName] = [SettingValue]
       My.Settings.Save()
End Sub
You could obviously elaborate on that also explore the methods and properties of the Settings class.

The other decent way is to do this:
Code:
Public Structure FileSettings
      <VBFixedString(244)>Dim SettingName As String
      Dim SettingValue As Object 'Unless you know what you would be saving
End Structure
'Effectively this acts as a record in a table within a database, just without the database
'and the table is a file
 
Public Sub WriteSettings()
      Dim newSetting As New FileSettings
      Dim settingStructureLength As Integer = Len(newSetting) 'Need to know how long each record is
      newSetting.SettingName = [SettingName]
      newSetting.SettingValue = [SettingValue]
      Dim ffInt As Integer = FreeFile() 'Find a free file in memory
      FileOpen(ffInt, [Filename/Filepath], Random, , , settingStructureLength) 'This opens, creates or what ever needs to be done to access that file
'The random means that it accesses any where in the file at specified points defined by
'the length of a record
      FilePut(ffInt, newSetting, 1) 'Put the object into the file
      FileClose(ffInt) 'This closes the file so that it can be later accessed and all that
End Sub
These aren't very comprehensive and its all done of the top of my head so some of it could be slightly wrong but i'm sure this is a good base for you to build on, i came up with all this on less prompts and with less knowledge(like no knowledge).

If you would like me to elaborate then just post back!
__________________
Apocolypse2005, I'm a programmer - of sorts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
auto generate & save text file marcusbris Visual Basic 2005 Basics 0 September 5th, 2007 01:43 AM
Auto populate/look up slim Access 6 May 31st, 2007 03:58 AM
Auto Refresh and Auto Delete deontae45 VB.NET 2002/2003 Basics 1 September 29th, 2006 04:53 PM
Auto updatoion anukagni Access 1 September 8th, 2006 06:33 AM
Auto Messaging anukagni Access 10 September 1st, 2006 11:54 PM





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