?
Solved

Reading registry

Posted on 2006-05-15
9
Medium Priority
?
251 Views
Last Modified: 2011-09-20
Once I've created several keys in the registry using SaveSettings, is there an easy way to enumerate all sections/keys?

For instance, if my hierarchy looks like

VB..Settings\MyAppName\MySection

and under MySection, I have

Folder1
Folder2
etc

and each FolderX has values of

Value1=100
Value2=200
Value3=300
etc

How can I easily loop through these acquiring the section/key names and values?


0
Comment
Question by:sirbounty
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 16681814
Hi sirbounty,

You might be able to iterate over the sections with an "Index". If you already know the number of sections, you can use something like this....

    Dim i As Long
    Dim n As Long
    For i = 1 to 6 '\\with 6 being the number of sections
        For n = 1 to 8 '\\with 8 being the number of values
            If GetSetting("MyAppName", "Folder" & i, "Value" & n, "") <> "" Then
                'do something
                'Folder = "Folder" & i
                'ValueName = "Value" & i
                'Value = GetSetting("MyAppName", "Folder" & i, "Value" & n, "")
            End If
        Next
    Next

If set the upper limit of both i and n to something that is known to be higher than that that actually exists, the code will continue to iterate over them, but will do nothing as GetSetting(...) will return "" if any of it's parameters are not found.

Regards,

Wayne
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 16681820
Correction....
 
     ValueName = "Value" & n
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16681854
Were these actually named Folder1, 2, etc, that might be feasible, but they're a bit more specific than that, unfortunately, with no counter.

I can retrieve everything I need using a command-line "reg query" loop.  I was hoping I could accomplish this without a shell though..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 1800 total points
ID: 16683167
You couls also use GetAllSettings.

This is Microsoft's example

GetAllSettings Function Example
This example first uses the SaveSetting statement to make entries in the Windows registry for the application specified as appname, then uses the GetAllSettings function to display the settings. Note that application names and section names can't be retrieved with GetAllSettings. Finally, the DeleteSetting statement removes the application's entries.

' Variant to hold 2-dimensional array returned by GetAllSettings
' Integer to hold counter.
Dim MySettings As Variant, intSettings As Integer
' Place some settings in the registry.
SaveSetting appname := "MyApp", section := "Startup", _
key := "Top", setting := 75
SaveSetting "MyApp","Startup", "Left", 50
' Retrieve the settings.
MySettings = GetAllSettings(appname := "MyApp", section := "Startup")
   For intSettings = LBound(MySettings, 1) To UBound(MySettings, 1)
      Debug.Print MySettings(intSettings, 0), MySettings(intSettings, 1)
   Next intSettings
DeleteSetting "MyApp", "Startup"


0
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 200 total points
ID: 16683177
Dim MySettings As Variant, cLoop As Integer
MySettings = GetAllSettings("MyApp", "Startup")
   For cLoop = LBound(MySettings, 1) To UBound(MySettings, 1)
      Debug.Print MySettings(cLoop, 0), MySettings(cLoop, 1)
   Next cLoop

'GetAllSettings read all the keys in a given location and creates an array, so loop among the array elements to read the keys.

S


0
 
LVL 19

Expert Comment

by:Shauli
ID: 16683184
Opps, GrahamSkan was faster...

S
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 16683317
Only by a minute - I didn't edit the example.
0
 
LVL 19

Expert Comment

by:Shauli
ID: 16683595
You should, don't you? :)

S
0
 
LVL 67

Author Comment

by:sirbounty
ID: 16686152
That gets me much closer at least.  I suppose that's about as close as I'll get going this route.
Thanx for the help!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question