README.md

December 4, 2022 ยท View on GitHub

A Beginner's INI Tutorial

Description

This is a simple project showing how to work with an INI file. It checks for the existence of the file, creates the file if needed, reads the settings and displays them. It allows writing new settings, refreshing the display on the fly. Please, comment on this if you find it useful, and as with all my submissions, I am not out for votes.

More Info

Submitted On2002-12-11 08:19:02
ByVBScript
LevelBeginner
User Rating4.9 (142 globes from 29 users)
CompatibilityVB 6.0
CategoryCoding Standards
WorldVisual Basic
Archive FileA_Beginner15115812112002.zip

API Declarations

'--------------------------------------------------------------------------
' This module makes writing to an INI file very easy. See the examples
' below for what needs to go into the VB code for this to work.
' Write Example:
' --------------
' WriteINI "Section", "Setting", Value, App.Path & "\settings.ini"
'
' Read Example:
' -------------
' Variable = ReadINI("Section", "Setting", App.Path & "\settings.ini")
'--------------------------------------------------------------------------
Option Explicit
Public Declare 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 Long, ByVal lpFileName As String) As Long
Public 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
Function ReadINI(Section As String, KeyName As String, FileName As String) As String
  Dim sRet As String
  sRet = String(255, Chr(0))
  ReadINI = Left(sRet, getprivateprofilestring(Section, ByVal KeyName$, "", sRet, Len(sRet), FileName))
End Function
Function WriteINI(sSection As String, sKeyName As String, sNewString As String, sFileName) As Integer
  Dim r
  r = writeprivateprofilestring(sSection, sKeyName, sNewString, sFileName)
End Function