VERSION 1.0 Class BEGIN CLASSBEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObjectENDAttribute VB_Name = "clsIniFile"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = False' Ini File Functions Class' Copyright (C) 1996, Jens Balchen'' Uses'' Exposes' Function GetSetting' Function SaveSetting' Function GetSection'' CommentsOption Explicit'Powered by barenx' --------' Public' --------'' Property for file to readPublic File As String' ---------' Private' ---------'' API to read/write ini's#If Win32 Then Private Declare Function GetPrivateProfileString()Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Private Declare Function WritePrivateProfileString()Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal Filename As String) As Integer#Else Private Declare Function GetPrivateProfileString()Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Private Declare Function WritePrivateProfileString()Function WritePrivateProfileString Lib "Kernel" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal Filename As String) As Integer#End IfSub DeleteSection()Sub DeleteSection(ByVal Section As String)Dim retval As Integer retval = WritePrivateProfileString(Section, 0&, "", File)End SubPublic Function SaveSetting()Function SaveSetting(ByVal Section$, ByVal Key$, ByVal Value$)Dim retval As Integer SaveSetting = WritePrivateProfileString(Section$, Key$, Value$, File)End FunctionPublic Function GetSetting()Function GetSetting(ByVal Section As String, ByVal KeyName As String) As StringDim retval As IntegerDim t As String * 255 ' Get the value retval = GetPrivateProfileString(Section, KeyName, "unknown value", t, Len(t), File) ' If there is one, return it If retval > 0 Then GetSetting = Left$(t, retval) Else GetSetting = vbNullString End IfEnd FunctionPublic Function GetSection()Function GetSection(ByVal Section As String, KeyArray() As String) As IntegerDim retval As Integer' Allocate space for return valueDim t As String * 2500Dim lastpointer As IntegerDim nullpointer As IntegerDim ArrayCount As IntegerDim keystring As String ReDim KeyArray(0) ' Get the value retval = GetPrivateProfileString(Section, 0&, "", t, Len(t), File) ' If there is one, return it If retval > 0 Then ' ' Separate the keys and store them in the array nullpointer = InStr(t, Chr$(0)) lastpointer = 1 Do While (nullpointer <> 0 And nullpointer > lastpointer + 1) ' ' Extract key string keystring = Mid$(t, lastpointer, nullpointer - lastpointer) ' ' Now add to array ArrayCount = ArrayCount + 1 ReDim Preserve KeyArray(ArrayCount) KeyArray(ArrayCount) = keystring ' ' Find next null lastpointer = nullpointer + 1 nullpointer = InStr(nullpointer + 1, t, Chr$(0)) Loop End If ' ' Return the number of array elements GetSection = ArrayCount End Function