'Module: ComProfile 'Purpose: get and set profiles strings from .ini files 'VB Version: Excel 97 SR-1 'Written by: David Crawford ' Option Explicit ' 'Purpose: Gets a profile values from ini files 'Arguments:
The section in the ini FileName ' The line in the ini FileName ' Default value for line ' Profile FileName 'Example: GetProfileString("ColWidths", "Col1", "17","DeleteMe.ini") ' Function GetProfileString( _ Section As String, _ Line As String, _ Default As String, _ FileName As String) As String On Error GoTo HandleErrors Dim ProfileString As String Dim PositionNull As Integer 'get string from .ini file ProfileString = Space(100) Call GetPrivateProfileString32(Section, Line, Default, ProfileString, 100, FileName) 'get postion of null PositionNull = InStr(1, ProfileString, Chr$(0)) 'if profile string is not empty If PositionNull > 1 Then 'remove trialing spaces and null GetProfileString = Left$(ProfileString, PositionNull - 1) 'if profile string is empty Else 'return empty string GetProfileString = "" End If ExitProcedure: Exit Function HandleErrors: MsgErr "getProfileString", Err Resume ExitProcedure End Function ' 'Purpose: Write a value to a .ini file 'Examples: SetProfileString "ColWidths", "Col1", "17","DeleteMe.ini" ' Sub SetProfileString( _ Section As String, _ Line As String, _ Value As String, _ File As String) On Error GoTo HandleErrors Call WritePrivateProfileString32(Section, Line, Value, File) ExitProcedure: Exit Sub HandleErrors: MsgErr "getProfileString", Err Resume ExitProcedure End Sub