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 / 309X3215.TXT < prev    next >
Encoding:
Text File  |  1998-05-05  |  1.1 KB  |  38 lines

  1.  
  2. Private Function RegRetrieve() As String
  3.  
  4. Dim lonSubkeyHandle As Long
  5. Dim lonStatus As Long
  6. Dim lonValueType As Long
  7. Dim lonValueSize As Long
  8.  
  9. ' Use the GetSubkeyHandle function to determine the
  10. ' handle of the subkey given in txtSectionName.
  11. lonSubkeyHandle = GetSubkeyHandle(txtSectionName.Text)
  12. If lonSubkeyHandle = -1 Then
  13.     ' Subkey could not be located.
  14.     RegRetrieve = "Error - Subkey could not be located"
  15.     Exit Function
  16. End If
  17.  
  18. ' Use the RegQueryValueEx API function to retrieve
  19. ' the value of the key given in txtKeyName.
  20. lonValueType = REG_SZ
  21. lonValueSize = 256
  22. lonStatus = RegQueryValueEx(lonSubkeyHandle, _
  23.     Trim$(txtKeyName.Text), 0, lonValueType, _
  24.     ByVal gstrKeyValue, lonValueSize)
  25. If lonStatus <> 0 Then
  26.     ' Key could not be located.
  27.     RegRetrieve = "Error - Key could not be located"
  28. Else
  29.     RegRetrieve = "Key retrieved successfully"
  30.     txtValue.Text = Left$(gstrKeyValue, lonValueSize)
  31. End If
  32.     
  33. ' Close the open subkey with the CloseSubKey
  34. ' function.
  35. lonStatus = CloseSubkey(lonSubkeyHandle)
  36.  
  37. End Function
  38.