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 / 309X3203.TXT < prev    next >
Encoding:
Text File  |  1998-05-05  |  1.5 KB  |  55 lines

  1.  
  2. Private Sub cmdRetrieve_Click()
  3.  
  4. Dim lonOpStatus As Long
  5.  
  6. ' Make sure both a key name and a section name
  7. ' have been specified by the user.
  8. If txtSectionName.Text = "" Then
  9.     MsgBox "Please enter a section name first."
  10.     Exit Sub
  11. End If
  12. If txtKeyName.Text = "" Then
  13.     MsgBox "Please enter a key name first."
  14.     Exit Sub
  15. End If
  16.  
  17. ' For INI files, call the INIRetrieve function. For
  18. ' the Registry, call the RegRetrieve function.
  19. If optType(0).Value = True Then
  20.     lblStatus = INIRetrieve()
  21. Else
  22.     lblStatus = RegRetrieve()
  23. End If
  24.  
  25. End Sub
  26.  
  27.  
  28. Private Function INIRetrieve() As String
  29.  
  30. Dim lonValueSize As Long
  31. Dim strSectionName As String
  32.  
  33. ' Remove brackets from section name, if necessary.
  34. strSectionName = FixSectionName(txtSectionName.Text)
  35.     
  36. ' Use the GetPrivateProfileString API function to
  37. ' retrieve the key's value from the file. A default
  38. ' value of "?!?" is used to see if the key has been
  39. ' retrieved successfully.
  40. lonValueSize = GetPrivateProfileString(strSectionName, _
  41.     txtKeyName.Text, "?!?", gstrKeyValue, 256, _
  42.     dlgGetFilename.FileName)
  43.     
  44. ' Determine the status of the operation. If the
  45. ' value of the key is the same as the default value
  46. ' ("?!?"), then the key was probably not found.
  47. If Left$(gstrKeyValue, 3) = "?!?" Then
  48.     INIRetrieve = "Error - Key could not be located"
  49. Else
  50.     INIRetrieve = "Key retrieved successfully"
  51.     txtValue.Text = Left$(gstrKeyValue, lonValueSize)
  52. End If
  53.  
  54. End Function
  55.