Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/06/2008, 08:25
Avatar de David
David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Cambiar definitivamente el calor de una variable

Copia ésto en un módulo:
Código:
 
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Public Enum Registry
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
    HKEY_CURRENT_CONFIG = &H80000005
End Enum
Private Const REG_SZ = 1
Sub regWrite(ByVal rLocal As Registry, ByVal SubKey As String, ByVal ValueName As String, ByVal Value As String)
On Error Resume Next
Dim hKey As Long
RegCreateKey rLocal, SubKey, hKey
RegOpenKey rLocal, SubKey, hKey
RegSetValueEx hKey, ValueName, 0, REG_SZ, ByVal Value, Len(Value)
RegCloseKey hKey
End Sub
Function regRead(ByVal rLocal As Registry, ByVal SubKey As String, ByVal ValueName As String) As String
On Error Resume Next
Dim Reply As Long
Dim DataSize As Long
Dim ValueType As Long
Dim GetValue As String
Dim hKey As Long
RegOpenKey rLocal, SubKey, hKey
Reply = RegQueryValueEx(hKey, ValueName, 0&, ValueType, ByVal 0&, DataSize)
If Reply = 0& Then
    If ValueType = REG_SZ Then
        GetValue = String(DataSize, Chr(0))
        Reply = RegQueryValueEx(hKey, ValueName, 0&, 0&, ByVal GetValue, DataSize)
        If Reply = 0& Then
            GetValue = Left(GetValue, InStr(1, GetValue, Chr(0)) - 1)
            regRead = GetValue
        End If
    End If
End If
RegCloseKey hKey
End Function
Sub regDelete(ByVal rLocal As Registry, ByVal SubKey As String)
Dim hKey As Long
RegOpenKey rLocal, SubKey, hKey
RegDeleteKey hKey, ""
RegCloseKey hKey
End Sub
Para guardar:
Código:
 
regWrite HKEY_LOCAL_MACHINE, "SOFTWARE\DavidElGrande", "nVal", CStr(nVal)
Para recuperar valor:
Código:
 
nVal = Val(regRead(HKEY_LOCAL_MACHINE, "SOFTWARE\DavidElGrande", "nVal"))
Saludos
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.