|
Private Sub RegistrySetKeyValue( _
eRootKey As EnumFormPosRegistryRootKeys, _ strKeyName As String, _ strValueName As String, _ strData As String) ' Comments : This procedure sets a key value ' Parameters: eRootKey - The root key ' strKeyName - The name of the key ' strValueName - The name of the value ' strData - The data to store in the value ' Returns : Nothing ' Dim lngRetVal As Long Dim lngHKey As Long On Error GoTo PROC_ERR ' Open the specified key, if it does not exist then create it lngRetVal = RegCreateKeyEx(eRootKey, strKeyName, 0&, vbNullString, _ mcregOptionNonVolatile, KEY_WRITE, 0&, lngHKey, 0&) strData = strData & vbNullChar lngRetVal = RegSetValueExString(lngHKey, strValueName, 0&, REG_SZ, _ strData, Len(strData)) RegCloseKey (lngHKey) PROC_EXIT: Exit Sub PROC_ERR: MsgBox "Error: " & Err.Number & ". " & Err.Description, , _ "RegistrySetKeyValue" Resume PROC_EXIT End Sub ' In the Declarations section of the form declare the variable Private mFormPos As CFormPos Private Sub Form_Load() ' Instantiate variable Set mFormPos = New CFormPos ' Assign current form to the Form property of the object Set mFormPos.Form = Me ' Assign alternative value to the AppName property mFormPos.RegistryPath = "SOFTWARE\FMS\Test CFormPos" mFormPos.SubKey = "Form Positions" ' restore to previously-saved locations. If not previously ' saved, then simply center the form If Not mFormPos.RestoreForm Then mFormPos.CenterForm End If End Sub Private Sub Form_Unload(Cancel As Integer) ' Save current position for next time mFormPos.SaveForm End Sub '---====[ pAssed by vbTips32 codeBook ]====--- |