borderAndreaVB free resources for Visual Basic developersborder
AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincani
:: Class to access INI Files

Author  

Andrea Rossignoli

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
Class Module

'***************************************************************
'CIni

Option Explicit

'API
Private Declare Function GetPrivateProfileInt Lib "kernel32.dll" _
Alias "GetPrivateProfileIntA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal nDefault As Long, _
ByVal lpFileName As String _
) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32.dll" _
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
Private Declare Function WritePrivateProfileString Lib "kernel32.dll" _
Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String _
) As Long

Private sFile As String

Public Sub Create(sFile_ As String)
    sFile = sFile_
End Sub

Public Property Get Data(sSection_ As String, sKey_ As String) As
Integer
    Data = GetPrivateProfileInt(sSection_, sKey_, -1, sFile)
End Property

Public Property Let Data(sSection_ As String, sKey_ As String, iData_
As Integer)
    Dim sData As String
    sData = iData_
    WritePrivateProfileString sSection_, sKey_, sData, sFile
End Property

Public Property Get Text(sSection_ As String, sKey_ As String) As String
    Dim sText As String
    Dim lResult As Long
    sText = String$(255, 0)
    lResult = GetPrivateProfileString(sSection_, sKey_, "", sText, Len(sText), sFile)
    If lResult = 0 Then
        Text = ""
    Else
        Text = Left(sText, InStr(sText, Chr(0)) - 1)
    End If
End Property

Public Property Let Text(sSection_ As String, sKey_ As String, sText_
As String)
    WritePrivateProfileString sSection_, sKey_, sText_, sFile
End Property
'*****************************************************************

:: Navigation

Home

Using the Registry

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 17-08-2006 IMPORT Data problem - zip codes (text) lose leading zero by ba1959nh
icon 03-10-2005 Re: Save Query "Image" problem by TJ_01
icon 25-09-2005 Save Query "Image" problem by dicky19
icon 08-04-2005 Re: check if FOLDER exist and if its EMPTY OR NOT? by JLRodgers
icon 15-09-2004 Re: Crystal Report & VB by amitsaxena
:: Sponsored Links



borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2017 Andrea Tincaniborder