Leer y escribir en un archivo INI (Visual Basic)

Option Explicit

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
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

Sub LeerINI()
On Error Resume Next
‘If FileExists(App.Path & “\Preferencias\config.ini”) =
True Then
varCambios = False
varCatRe = ReadINI(“Categoría”, “Reemplazar”, “1″)
‘Else
‘varCambios = False
‘varVerCat = “”
‘End If
End Sub

Sub GuardarINI()
On Error Resume Next
WriteINI “Categoría”, “Reemplazar”, CStr(varCatRe)
WriteINI “Categoría”, “Mostrar”, varVerCat
End Sub

Function ReadINI(strSection As String, strSetting As String,
strDefault As String)
Dim lngReturn As Long, strReturn As String, lngSize As Long
lngSize = 255
strReturn = String(lngSize, 0)
lngReturn = GetPrivateProfileString(strSection, strSetting,
strDefault, strReturn, lngSize, App.Path &
“\Preferencias\config.ini”)
If strReturn = “” Then
ReadINI = strDefault
WriteINI strSection, strSetting, strDefault
Else
ReadINI = LeftOf(strReturn, Chr(0))
End If
End Function

Function WriteINI(strSection As String, strLValue As String,
strRValue As String)
Dim lngReturn As Long
lngReturn = WritePrivateProfileString(strSection, strLValue,
strRValue, App.Path & “\Preferencias\config.ini”)
End Function

Function LeftOf(strData As String, strDelim As String) As String
Dim intPos As Integer

intPos = InStr(strData, strDelim)
If intPos Then
LeftOf = Left(strData, intPos – 1)
Else
LeftOf = strData
End If
End Function

3 comentarios en “Leer y escribir en un archivo INI (Visual Basic)

  1. hola JbX, perdona por mi tardanza. Estoy un poco liado.

    He escrito un nuevo post que te da una alternativa creo que mas estable.

    Puedes verlo aqui.

  2. en Visual Studio 2008 no me permite declarar ‘ByVal lpKeyName As Any’ no se puede declarar Any me sale error cual seria la solucion?? gracias

Los comentarios están cerrados.