Guardar Configuracion en Ini
Buenas, te paso un ejemplo echo con Api, las funciones son de [Ex3] http://www.canalvisualbasic.net/forum/forum_posts.asp?TID=25329&PN=1
'un un form poner 3 Option, 1 combo. tendras que ejecutarlo 2 veces para que te cree el archivo ini. te guardara la posicion/tamaño del form, el option seleccionado y el iten del combo seleccionado
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
Dim NumSel As Integer, ItemSel As Integer
Dim Ruta As String
'Funcion de lectura:
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
'Se define el tamaño maximo de caracteres
'que podra tener la variable Value:
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
'Metodo de escritura. Si el archivo al que se refiere el parametro Filename
'no existe se crea automaticamente:
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
'Escribimos el valor de la clave:
Size = WritePrivateProfileString(Key_Value, Key_Name, Value, Filename)
ErrOut:
End Sub
Private Sub Combo1_Click()
ItemSel = Combo1.ListIndex
End Sub
Private Sub Form_Load()
Ruta = App.Path & "\config.ini"
For i = 1 To 10
Combo1.AddItem i
Next
If (Dir(Ruta) <> "") Then
NumSel = INI_Read(Ruta, "Opciones1", "NumSel")
ItemSel = INI_Read(Ruta, "Combo1", "ItemSel")
Form1.Top = INI_Read(Ruta, "Formulario", "Top")
Form1.Left = INI_Read(Ruta, "Formulario", "Left")
Form1.Width = INI_Read(Ruta, "Formulario", "Width")
Form1.Height = INI_Read(Ruta, "Formulario", "Height")
Select Case NumSel
Case 1
Option1 = True
Case 2
Option2 = True
Case 3
Option3 = True
End Select
Combo1.ListIndex = ItemSel
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
INI_Write Ruta, "Formulario", "Top", Form1.Top
INI_Write Ruta, "Formulario", "Left", Form1.Left
INI_Write Ruta, "Formulario", "Width", Form1.Width
INI_Write Ruta, "Formulario", "Height", Form1.Height
INI_Write Ruta, "Opciones1", "NumSel", NumSel
INI_Write Ruta, "Combo1", "ItemSel", ItemSel
End Sub
Private Sub Option1_Click()
NumSel = 1
End Sub
Private Sub Option2_Click()
NumSel = 2
End Sub
Private Sub Option3_Click()
NumSel = 3
End Sub
'