Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2006, 04:37 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to load settings for my app

Hi there, I hope u can help me with this:
I've made an app that compares numbers in a list against other numbers in a txt file.

I also put an option that lets the user store the numbers he/she introduced in a txt file for further use.

When you start the app it automatically loads the numbers in the txt (that the user saved )into the list. My problem is this, i want to implement a checkbox to trigger this event(autoload numbers). If the user have this checkbox ticked when the app loads then autoload...

How can i make a file that remembers the settings of my app?

Reply With Quote
  #2 (permalink)  
Old October 31st, 2006, 06:35 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

If you let the application wizard create an app for you, you will see an implementation of using the registry to store application setting (window size and position).

Just adapt that ability to your own particular case. If the box is checked, get the data that is at the location you last stored in the registry. Or when the app is closed store the state of the checkbox. the possibilities are almost endless.

(I'm not saying that you need to abandon your app, and create it afresh with the wizard. I'm only sayijng that using the wizard to create a blank app will generate a sample for you to go by.)
Reply With Quote
  #3 (permalink)  
Old October 31st, 2006, 06:49 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian is suggesting that you use the registry to store the info about the checkbox, and this is one of the standard ways to do this.

However, you could also use a simple text file that you store along with the application exe to contain any configuration values. It could also be an xml file, but that will be overkill for your current use.

If the file doesn't exist you will simply use a hard-coded default for any value you want the user to be able to configure. Whenever the user changes a configurable value you would save it to the file. If the file doesn't exist, your code would create it. Since you are already working with text files in your application you probably already know how to implement this.

Additionally, if you are only using one text file for your list of numbers you could add "metadata" to that file. Your code save to that file the additional information about autoloading, and read it on start up. For example, the first line of the file could be AUTOLOAD=TRUE, or something like that. Get it?

In the "old days" many windows applications had an INI file, which was a file with the .ini extension (with ini standing for initialization), and contained (mostly) key/value pairs, more or less. Along the way, the registry became the preferred method for storing this sort of configuration. Now, many applications are moving back to using a "private" configruation file.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #4 (permalink)  
Old November 1st, 2006, 03:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:[i]... Now, many applications are moving back to using a "private" configruation file...
woody, where did you get this idea from?
I find the storing "user" configuration data in the registry is much more powerful (which user can have different settings) and the VB methods to access the registry very simple to use.
For "global" configuration data (that is, not user dependent) it is fair game... :)
Reply With Quote
  #5 (permalink)  
Old November 1st, 2006, 03:22 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the suggestions, i did this: At the unload event, i saved all the properties of the objects, i wanted to remember into a string; which i saved in a txt named "settings.txt".
Then at the load event i read them.
I would like to try the registry method though, but i was running out of time.


Reply With Quote
  #6 (permalink)  
Old November 1st, 2006, 06:32 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by marcostraf
 
Quote:
quote:[i]... Now, many applications are moving back to using a "private" configruation file...
Quote:
woody, where did you get this idea from?
I work in .NET (mostly C#) and a great deal of metadata is stored in what are called "config" files. These are highly customizable and very powerful from an object oriented point of view. .NET also provides a strong set of framework classes for working with config files. I am not saying it is better or worse in all cases. On the other hand, in many cases where the configuration is complex or hierarchical, the XML model and capacity for large amounts of data it is ideal. There is still some setup information in the registry, but most of it is in the config files.

Additionally, highly configurable applications that use "plug-in" style ideas for extensibility often use config files for carrying metadata.

As for user dependent configuration, I typically use the database (if the application uses one) or encrypted XML files, and never use the registry. For example, the app I am currently working with has about 2 million lines of code in the core components and for the UI component all the treeviews and listview are completely configurable by the user. If the user moves from one machine to another (which can happen at every shift change) it would be a nightmare to somehow synchronize each machines registry each time a user changes a prefernce. All of this configuration resides in the database, and is therefore available to each user regardless of the machine they are working at.

As I say - there are at least 1000 right ways to do anything, and the first one you find is the one to use until you find some reason to use another. For me, there are a few things I find the registry useful for, but very few anymore.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #7 (permalink)  
Old November 1st, 2006, 07:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by woodyz... there are at least 1000 right ways to do anything, and the first one you find is the one to use until you find some reason to use another. For me, there are a few things I find the registry useful for, but very few anymore.
...
I agree, completely
not all of our applications use a database, so I cannot use that option, plus we do not have the problem of user shifting computers, so the registry is perfect for us for storing user settings. But, as I said, all our configuration is stored in files.
Reply With Quote
  #8 (permalink)  
Old November 18th, 2006, 08:10 PM
Friend of Wrox
Points: 1,075, Level: 12
Points: 1,075, Level: 12 Points: 1,075, Level: 12 Points: 1,075, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2005
Location: , , United Kingdom.
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Wouldn't configuration files be more useful because of changing computers seeing as you can quickly do like a transfer settings, which would be just copying across the configuration file?? Or could that be easily done with registry?
Reply With Quote
  #9 (permalink)  
Old November 20th, 2006, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it is not easily done with the registry (although it is possible using export/import from the registry)
As Woody stated, if the user switches computer it is better to store the settings in a file that can be easily accessed/moved/copied (unless you have network connection with a global database
Reply With Quote
  #10 (permalink)  
Old November 20th, 2006, 02:32 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is easy enough to export and import values from the registy or to copy the file from computer to computer, but another solution (if you don't have a databse available) is to store the file on a network drive that is accessible from all computers where the application runs, and store the info for each user in a single file.

However, if you do work with a local file you could store the info in the users documents folder so there can be numerous users on a single machine, each with their own settings, and so that users wouldn't then overwrite other users files as they go from machine to machine.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
02 IN 01 Desktop App (App+Wind Handler) pk_ocp .NET Framework 2.0 0 February 26th, 2008 02:58 PM
Changing Settings.settings when assembly is in GAC evandro.paula .NET Framework 2.0 0 September 25th, 2007 09:54 AM
Convert a VB.Net app to a web app? furjaw VB.NET 3 September 24th, 2007 12:27 PM
How to load a file into your own app? Apocolypse2005 Beginning VB 6 2 October 25th, 2006 03:59 PM
Error on local load of downloaded app Gjerstad BOOK: ASP.NET Website Programming Problem-Design-Solution 4 June 21st, 2003 10:36 AM



All times are GMT -4. The time now is 07:40 PM.


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