Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/12/2011, 15:03
Avatar de lokoman
lokoman
 
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 6 meses
Puntos: 47
Respuesta: Leer archivo .ini

Hola!
Este es mi aporte:

En un modulo:

Código vb:
Ver original
  1. 'INI
  2. 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
  3. 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
  4.  
  5. Public Function LeerINI(strClave As String, strNombre As String, Optional ByVal strDefecto As String) As String
  6.     Dim intTamano As Integer
  7.     Dim strTexto As String
  8.     Dim strArchivoINI As String
  9.    
  10.     strArchivoINI = App.Path & "\Config.INI"
  11.     strTexto = Space(200)
  12.     intTamano = GetPrivateProfileString(strClave, strNombre, "", strTexto, Len(strTexto), strArchivoINI)
  13.    
  14.     If intTamano > 0 Then
  15.         strTexto = Left$(strTexto, intTamano)
  16.     Else
  17.         strTexto = ""
  18.     End If
  19.    
  20.     If Len(strTexto) Then
  21.         LeerINI = strTexto
  22.     Else
  23.         LeerINI = strDefecto
  24.     End If
  25. End Function
  26.  
  27. Public Function EscribirINI(strClave As String, strNombre As String, strTexto As String) As String
  28.     Dim intTamano As Integer
  29.     Dim strArchivoINI As String
  30.    
  31.     strArchivoINI = App.Path & "\Config.ini"
  32.    
  33.     intTamano = WritePrivateProfileString(strClave, strNombre, strTexto, strArchivoINI)
  34. End Function


• Uso para escribir:
strRuntime = EscribirINI("CLAVE", "NOMBRE", TEXTO)

• Uso para Leer:
strRuntime = LeerLicencia("CLAVE", "NOMBRE", "VALOR DEFAULT")

El "VALOR DEFAULT" es el valor por defecto si no se encuentra el valor de la llave "NOMBRE"


Esta es la composicion archivo .ini:
[CLAVE]
NOMBRE=lokoman


!!