'=========================================================================== ' Subject: READ & WRITE INI FILES Date: 06-28-00 (18:14) ' Author: Gerome Guillemin Code: RAPIDQ ' Origin: gguillemin@bvrp.com Packet: RAPIDQ.ABC '=========================================================================== '///////////////////// BEGIN //////////////////////////////// ' PURPOSE : Writing & reading with Ease into an INI File ' Originally issued from a VB Sample ' Turned into Rapid-Q's way of life by Gerome GUILLEMIN ' - http://gedd123.free.fr - mailto : gedd123@free.fr - 'June 29th 2000 'Feel Free to use this Code - 'This Code is dedicated to the Rapid-Q's Community and all lovers of Basic Code ! 'Please Mention the '@' character to avoid an empty value (Byval needs this sometimes) $TypeCheck ON $Define MAX_PATH 260 'API declarations Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, ByVal lpKeyName As String, _ ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" _ (ByVal lpApplicationName$, ByVal lpKeyName As String, lpString As String, ByVal lpFileName$) As Long 'User's Variables Dim iLenght As Integer Dim szReturn As String Dim svReturn as String Dim szReturned as String szReturned = Space$(MAX_PATH) 'Dimension a buffer 'Main Function to GET information into an INI File Function GetIni(szSection As String, svVariant As String, szFile As String) As String iLenght = GetPrivateProfileString(szSection, svVariant, "", @szReturned, MAX_PATH, szFile) szReturned = Left$(szReturned, iLenght) GetIni = szReturned End Function 'Main Function to WRITE information from an INI File Function WriteIni(szSection As String, svVariant As String, svValue As String, szFile As String) As Integer WritePrivateProfileString szSection, svVariant, svValue, szFile End Function 'To Write into your Favourite INI File you ca use these 2 wayz... iLenght = WriteIni("Header", "Title", "Valuez", "c:\MyINI.ini") 'or... call WriteIni("Header", "Title", "Valuez", "c:\MyINI.ini") Sleep 1 '... after that it'll be time to read ! 'To read a Value OR a String in an INI File, you just have to type this :) svReturn = GetIni("Header", "Title", "c:\MyINI.ini") ShowMessage svReturn 'Ciao bye-bye :) Application.Terminate '///////////////////////// END ////////////////////