Consulting

Results 1 to 10 of 10

Thread: Solved: Using the Registry in an Application

  1. #1

    Solved: Using the Registry in an Application

    In J. Walkenbach's VBA book he mentions briefly that an application can use the Registry to store info. That tweaked my interest. I found several related statements in the Help, but it wasn't overly explanatory. My question is: Has anyone used the Registry to store info for an application, and what are the goods and bads about doing that?

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Oh yes, many times!

    It gives you a way of ensuring your values stay, without having to worry about hiding things in sheets, or keeping settings between sessions.

    I had one app that I built where we used an Addin to import, reformat and save text files. I stored a number in the registry that incremented by one every time the procedure ran, and used that number in the file save name. I preferred doing it that way to resaving the addin all the time. It also meant that you could install it on multiple machines, and they would get their own sequence.

    VBA has a GetSetting and SaveSetting function, which you can find in the help. There are also other ways to write to the registry, but with the aforementioned two, they go into a relatively safe place, although I can't remember the exact hive.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Malcolm, that's perfect!

    I think that there's some other registry ones in there as well.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    Hey, Malcolm, just what I was lookiing for. Thanks, guy!

  6. #6
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Hi all,

    I can agree that SaveSetting / GetSetting is easy to use but they are limit in that they can only operate with a minor part of the registry.

    In addition to them there exist alternative approaches like the following example here shows: http://www.mrexcel.com/board2/viewto...5&highlight=vb

    If we want to fully control the registry then Windows API is the way to go:

    How To Use the Registry API to Save and Retrieve Setting
    http://support.microsoft.com/default...b;en-us;145679

    How to write to the Windows registry by using Windows API calls
    http://support.microsoft.com/default...b;en-us;135398

    How To Read from the Windows Registry
    http://support.microsoft.com/default...b;en-us;140170

    Kind registry-regards,
    Dennis
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Best advice to go with that, though.. BE CAREFUL!

    The thing I like about Get/Save setting is that they go into a place I know is benign as far as affecting other areas. You don't have that same confirmation if you start placing your own keys elsewhere, or expecially editing others.

    I'm not saying don't do it, by any means. Joost will tell you that it's why I have issues with my PC since I'm rarely afraid to jump in there . Just be careful when you do it. Make a registry backup before you play, and remember what you did.

    Cheers!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'll go along with Ken on that. Although I have never had a practical need for Save/Get Settings, I would cetainly look at saving or reading data first from a text file or similar, especially in a network situation.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Hey, guys, a lot of great discussion on this. I've been enightened (but I still weigh the same).

  10. #10
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    I usually categorize the needs for working with the registry into three groups:

    User settings, which Save-/GetSetting is the simplest way to handle this kind of info.

    Application settings, license and other more confidential information which Windows API is the best approach.

    Installation settings, subject to which kind of application to be shipped, i e one of the above or with help of a installation software.

    The above is similar for both client or serverinstallation.

    Working with the registry put a high demand that we know what we are doing and in a learning process I fully agree with Ken about backup. Another option is to restore the Windows settings to a specific restore point via Windows.

    Kind registry-regards,
    Dennis
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •