
24/03/2009, 22:53
|
| | Fecha de Ingreso: marzo-2009
Mensajes: 23
Antigüedad: 16 años, 1 mes Puntos: 0 | |
VB Config.ini no encuentra los valores... por favor Señores:
Gracias por su colaboracion.
Estoy leyendo un archivo config.ini, pero me retorna valores en vacio ("").....
Por favor... que estoy escribiendo mal o que me falta..... Gracias
/********* Aplicacion VB ***********/
Option Explicit
Private 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
Private 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
Private Declare Function FileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
Public Function INI_Read(ByVal Filename As String, ByVal Key_Value As String, ByVal Key_Name As String, Optional ByVal Default As String) As String
On Error GoTo ErrOut
Dim Size As Integer
Dim Value As String
If Not CBool(FileExists(Filename)) Then Err.Raise 53
Value = Space(256)
'Se utiliza la función para obtener el valor de la clave:
Size = GetPrivateProfileString(Key_Value, Key_Name, Default, Value, Len(Value), Filename)
'Si el tamaño es mayor a 0 entonces
'se ha encontrado el valor de la clave:
If Size > 0 Then
Value = VBA.Left$(Value, Size)
'Devolvemos el valor de la clave:
If VBA.Right$(VBA.Trim$(Value), 1) = Chr(0) Then Value = VBA.Left$(VBA.Trim$(Value), Len(VBA.Trim$(Value)) - 1)
INI_Read = VBA.Trim$(Value)
Exit Function
End If
ErrOut:
INI_Read = Default
End Function
Public Sub INI_Write(ByVal Filename As String, ByVal Key_Value As String, ByVal Key_Name As String, ByVal Value As String)
On Error GoTo ErrOut
Dim Size As Integer
Size = WritePrivateProfileString(Key_Value, Key_Name, Value, Filename)
ErrOut:
End Sub
Private Sub Form_Load()
Servidor = INI_Read("Config.ini", "Conexion", "Servidor")
BaseDatos = INI_Read("Config.ini", "Conexion", "BaseDatos")
Login = INI_Read("Config.ini", "Conexion", "Login")
Password = INI_Read("Config.ini", "Conexion", "Password")
ConxStr = "Driver={SQL Server};Server=" & Servidor & ";Database=" & BaseDatos & ";Uid=" & Login & ";Pwd=" & Password & ";"
Conexion.Open ConxStr
SQLStr = "Select * from PPTO_Ejecucion order by Id_Ejecucion"
Call Abre_Tablas(SQLStr, 1)
Do While Not Registros.EOF
Cmb_Ejecucion.AddItem Registros.Fields!Descripcion
Registros.MoveNext
Loop
End Sub
/********* Config.ini ***********/
[Conexion]
Servidor=Server
Basedatos=SqldataBase
Login=AdminUser
Password=magia |