VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Beginner's INI Tutorial

by VBScript (17 Submissions)
Category: Coding Standards
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (29 Votes)

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.

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

Rate A Beginner's INI Tutorial

Download A Beginner's INI Tutorial

Download A Beginner's INI Tutorial (4 KB)

A Beginner's INI Tutorial Comments

No comments have been posted about A Beginner's INI Tutorial. Why not be the first to post a comment about A Beginner's INI Tutorial.

Post your comment

Subject:
Message:
0/1000 characters