Attribute VB_Name = "Module1"
Option Explicit

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'INI File Declare WinAPI

' Below function is used to READ from INI file(All One Line)
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

' Below function is used to WRITE to INI file(All One Line)
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long


'Variables used for the INI file reading and writing.....
Dim nSize As Long
Dim lpDefault As String
Dim lpFileName As String
Dim lpFile As String
Dim ret As Long
Dim INIFileCreated As Boolean

Public Sub CreateINIFile(File As String)
    INIFileCreated = False
    'Create INI File
    lpFile = File
    lpFileName = App.Path & "\" & File
    
End Sub

Public Sub CreateINIApp(lpAppName As String)
    'Create INI [App] value
    If Dir(lpFileName) <> lpFile Or INIFileCreated Then
        INIFileCreated = True
        Open lpFileName For Append As #1
        Print #1, "[" & lpAppName & "]"
        Close #1 'Close the file...
    End If
End Sub

Public Sub CreateINIKey(lpAppName As String, lpKeyName As String, DefaulKey As String)
    'Create INI Key= value
    If INIFileCreated Then
        Open lpFileName For Append As #1
        Print #1, lpKeyName & "="
        Close #1
        Call WriteINI(lpAppName, lpKeyName, DefaulKey)
    End If
End Sub


Public Function ReadINI(lpAppName As String, lpKeyName As String)
    Dim lpBuffer As String
    'lpBuffer is what will be read from the file. The 255 makes sure that only the first 255
    'characters will be read. A line in your INI file shouldn't be that long anyway...
    lpBuffer = Space(255)
    nSize = 255
    
    'The below line reads the information from the file
    'using the 6 INI file variables and stores the info read into the lpBuffer variable.
    ret = GetPrivateProfileString(lpAppName, lpKeyName, lpDefault, lpBuffer, nSize, lpFileName)
    
    ReadINI = lpBuffer
End Function


Public Sub WriteINI(lpAppName As String, lpKeyName As String, lpBuffer As String)
    'The below line writes the information to the INI file
    'using 4 of the 6 INI file variables. lpBuffer is always
    'the data that is going to be written to the INI file.
    ret = WritePrivateProfileString(lpAppName, lpKeyName, lpBuffer, lpFileName)
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
