VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



INI Reading and Writing Made Simple

by Austen Frazier (1 Submission)
Category: Miscellaneous
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This code was designed for reading and writing INI files. You put it in a module called modINI.

Inputs
Syntax: ReadINI("SECTION", "FIELD", filename) WriteINI("SECTION", "FIELD", "VALUE", filename)
Assumes
This is very "newbie" friendly code. Any user, from beginner to advanced user, can use it.
Code Returns
The value of the field read from the INI for ReadINI. For WriteINI, it will return nothing.

Rate INI Reading and Writing Made Simple

Option Explicit
'ModINI.Bas
'INI reading/writing
Public Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
Public Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnedString$, ByVal RSSize&, ByVal FileName$)
Public Sub WriteINI(INISection As String, INIKey As String, INIValue As String, INIFile As String)
  Call WritePrivateProfileString(INISection, INIKey, INIValue, INIFile)
End Sub
Public Function ReadINI(INISection As String, INIKey As String, INIFile As String) As String
  Dim StringBuffer As String
  Dim StringBufferSize As Long
  
  StringBuffer = Space$(255)
  StringBufferSize = Len(StringBuffer)
  
  StringBufferSize = GetPrivateProfileString(INISection, INIKey, "", StringBuffer, StringBufferSize, INIFile)
  
  If StringBufferSize > 0 Then
    ReadINI = Left$(StringBuffer, StringBufferSize)
  Else
    ReadINI = ""
  End If
End Function

Download this snippet    Add to My Saved Code

INI Reading and Writing Made Simple Comments

No comments have been posted about INI Reading and Writing Made Simple. Why not be the first to post a comment about INI Reading and Writing Made Simple.

Post your comment

Subject:
Message:
0/1000 characters