Click here to Skip to main content
14,835,987 members
Articles / Programming Languages / Visual Basic
Posted 29 Apr 2008

Tagged as


14 bookmarked

Advanced Collection for VB6 Application Settings

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
29 Apr 2008GPL33 min read
Advanced Collection (like ASP.NET name/value collection) for VB6 Application settings


In this article, I tried to implement the following things:

  1. Manipulate application configuration data and settings as Name Value collection
  2. Provide advanced GetSetting and SaveSetting functions
  3. Provide advanced INI file handling
  4. Implement escape sequence characters for settings


VB6 provides GetSetting and SaveSetting functions to programmers to manipulate application settings. These settings are stored in HKEY_CURRENT_USER \ Software \ VB and VBA Program Settings\ location of the windows registry.


  1. Note that these settings store under current user settings of registry. So in multi user Windows system, each user may have different settings.
  2. Since the speed of Windows depends up on the Windows registry size also, we can't store a large amount of information on the registry.
  3. Moving configuration data from one machine to another machine is very hard.
    Please note that the earlier version of Windows provides 2 functions namely
    getprivateprofilestring, writeprivateprofilestring for manipulation of application data by using files. But Microsoft states that "This function is provided only for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry."

    So I implemented Name Value collection in VB6 to read and write settings of an application from a text file so that we can easily move the application from one machine to another machine.

Using the Code
'Assigns filename to collection to perform operation
Settings.FileName = "ConverterSettings.ini"

'Load collection items from file 

'Save collection to file

'Add / Modify an item
CollectionName("Name/Key") = value

'Remove an item
CollectionName.Remove(index / Key)

'Replacement of GetSetting function
Public Function GetMySetting(AppName As String, Section As String, _
            Key As String, Optional Default As String) As String
    GetMySetting = Settings.GetItem(AppName & "_" & Section & "_" & Key,_
              , Default)
End Function

'Replacement of SaveSetting function
Public Function SaveMySetting(AppName As String, Section As String, _
            Key As String, Setting As String)
    Settings(AppName & "_" & Section & "_" & Key) = Setting
End Function

List of functions implemented on class module and their meaning:

Name Usage Scope Type
ProcessEscapeSequence Converts escape sequence characters Private Function
ProcessINIContents Parses file content to string lines Private Subroutine
ProcessLine Load Keys and values from file lines Private Subroutine
Add Adds new item to collection Public Function
Count Returns number of items in collection Public Property Get
GetItem Reads an item safely from collection Public Function
LoadContents Loads collection from file Public Function
Remove Removes an item from collection Public Subroutine
SaveCollectionToFile Saves contents of collection to a file Public Function

Points of Interest

I added a module that processes file and Windows operations with proper status codes with this article.

Name Usage Scope Type
ExplorerOpen Open a file in explorer Public Subroutine
ExplorerShowFile Locate a file in explorer Public Subroutine
FileAppend Append information to file Public Function
FileAppendString Append string to file Public Function
FileExists Check file exists in particular location or not Public Function
FileKillSafe Kill a file from disk Public Function
FileMakeString Replace file contents with a string Public Function
FileRead Read file contents as bytearray Public Function
FileReadString Read contents of a file in string format Public Function
FileStore Store binary information(byte array) to a file Public Function
FillCombo Fill a combo from file content string Public Subroutine
FolderExists Check folder exists in given path or not Public Function
FolderKill Delete this directory and all the SubFolders it contains. Public Function
GetMySetting Replacement of GetSetting function Public Function
PathFileName Get file name part of full file path Public Function
PathParent Get Parent folder name Public Function
PathRemoveSlash Remove slash from right most end Public Function
ProcessExecuteandWait Execute a file and wait for it to finish Public Function
SaveMySetting Replacement of SaveSetting function Public Function
StringStripNull Return a string without the chr$(0) terminator. Public Function
WindowsTemporaryFolder Get windows temporary folder path Public Function


  • Version 1 released on April 20, 2008


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Sabarinathan A
India India
I have been programming for last 20 years on various platforms including .NET, Visual Basic 6, Oracle and SQL server.

I decided to write articles when I have free time hoping to share my thoughts with you.

To know more about me visit

Comments and Discussions

QuestionAre some code segments missing? Pin
cvmarty26-Apr-14 2:29
Membercvmarty26-Apr-14 2:29 
Generalbest regards Pin
mas fauzan15-Jan-09 21:10
Membermas fauzan15-Jan-09 21:10 
QuestionVB6? Pin
evolved30-Apr-08 6:48
Memberevolved30-Apr-08 6:48 
AnswerRe: VB6? [modified] Pin
Sabarinathan A1-May-08 19:16
professionalSabarinathan A1-May-08 19:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.