Click here to Skip to main content
Click here to Skip to main content

Tagged as

Advanced Collection for VB6 Application Settings

, 29 Apr 2008
Rate this:
Please Sign up or sign in to vote.
Advanced Collection (like ASP.NET name/value collection) for VB6 Application settings

Introduction

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

Background

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.

Disadvantages

  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 
Settings.LoadContents

'Save collection to file
Settings.SaveCollectionToFile

'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

History

  • Version 1 released on April 20, 2008

License

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

Share

About the Author

Sabarinathan A
Technical Lead Tech Mahindra
India India
I have been programming for last 10 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 http://sabarinathanarthanari.com
Follow on   Twitter

Comments and Discussions

 
QuestionVB6? Pinmemberevolved30-Apr-08 6:48 
AnswerRe: VB6? [modified] PinmemberSabarinathan Arthanari1-May-08 19:16 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 29 Apr 2008
Article Copyright 2008 by Sabarinathan A
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid