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 / 309X3204.TXT < prev    next >
Encoding:
Text File  |  1998-05-05  |  1.2 KB  |  49 lines

  1.  
  2. Private Sub cmdUpdate_Click()
  3.  
  4. ' Make sure both a key name and a section name
  5. ' have been specified by the user.
  6. If txtSectionName.Text = "" Then
  7.     MsgBox "Please enter a section name first."
  8.     Exit Sub
  9. End If
  10. If txtKeyName.Text = "" Then
  11.     MsgBox "Please enter a key name first."
  12.     Exit Sub
  13. End If
  14.  
  15. ' For INI files, call the INIUpdate function. For
  16. ' the Registry, call the RegUpdate function.
  17. If optType(0).Value = True Then
  18.     lblStatus = INIUpdate
  19. Else
  20.     lblStatus = RegUpdate
  21. End If
  22.  
  23. End Sub
  24.  
  25.  
  26. Private Function INIUpdate() As String
  27.  
  28. Dim lonStatus As Long
  29. Dim strSectionName As String
  30.  
  31. ' Remove brackets from section name, if necessary
  32. strSectionName = FixSectionName(txtSectionName.Text)
  33.  
  34. ' Use the WritePrivateProfileString API function to
  35. ' update the key.
  36. lonStatus = WritePrivateProfileString(strSectionName, _
  37.     txtKeyName.Text, txtValue.Text, dlgGetFilename.FileName)
  38.     
  39. ' Display the status of the operation and update
  40. ' the file contents list box if successful.
  41. If lonStatus = 0 Then
  42.     INIUpdate = "Error - Key could not be updated"
  43. Else
  44.     INIUpdate = "Key updated successfully"
  45.     ReadFile
  46. End If
  47.  
  48. End Function
  49.