home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 6 Unleashed…sional Reference Edition) / Visual_Basic_6_Unleashed_Professional_Reference_Edition_Sams_1999.iso / Source / CHAP29 / 309X3217.TXT < prev    next >
Encoding:
Text File  |  1998-05-05  |  1.7 KB  |  68 lines

  1.  
  2. Private Function RegUpdate() As String
  3.  
  4. Dim lonSubkeyHandle As Long
  5. Dim lonStatus As Long
  6.  
  7. ' Use the GetSubkeyHandle function to determine the
  8. ' handle of the subkey given in txtSectionName.
  9. lonSubkeyHandle = GetSubkeyHandle(txtSectionName.Text)
  10. If lonSubkeyHandle = -1 Then
  11.     ' Subkey could not be located.
  12.     RegUpdate = "Error - Subkey could not be located"
  13.     Exit Function
  14. End If
  15.  
  16. ' Use the RegSetValueEx API function to update the
  17. ' key's value.
  18. lonStatus = RegSetValueEx(lonSubkeyHandle, _
  19.     txtKeyName.Text, 0, REG_SZ, ByVal txtValue.Text, _
  20.     Len(txtValue.Text))
  21.  
  22. ' Check status of the operation.
  23. If lonStatus <> 0 Then
  24.     RegUpdate = "Error - Key could not be updated"
  25. Else
  26.     RegUpdate = "Key updated sucessfully"
  27. End If
  28.  
  29. ' Close the open subkey with the CloseSubKey
  30. ' function.
  31. lonStatus = CloseSubkey(lonSubkeyHandle)
  32.  
  33. End Function
  34.  
  35.  
  36. Private Function RegAdd() As String
  37.  
  38. Dim lonSubkeyHandle As Long
  39. Dim lonStatus As Long
  40.  
  41. ' Use the GetSubkeyHandle function to determine the
  42. ' handle of the subkey given in txtSectionName.
  43. lonSubkeyHandle = GetSubkeyHandle(txtSectionName.Text)
  44. If lonSubkeyHandle = -1 Then
  45.     ' Subkey could not be located.
  46.     RegAdd = "Error - Subkey could not be located"
  47.     Exit Function
  48. End If
  49.  
  50. ' Use the RegSetValueEx API function to create a
  51. ' new key and set its value.
  52. lonStatus = RegSetValueEx(lonSubkeyHandle, _
  53.     txtKeyName.Text, 0, REG_SZ, ByVal txtValue.Text, _
  54.     Len(txtValue.Text))
  55.  
  56. ' Check status of the operation.
  57. If lonStatus <> 0 Then
  58.     RegAdd = "Error - Key could not be added"
  59. Else
  60.     RegAdd = "Key added sucessfully"
  61. End If
  62.  
  63. ' Close the open subkey with the CloseSubKey
  64. ' function.
  65. lonStatus = CloseSubkey(lonSubkeyHandle)
  66.  
  67. End Function
  68.