home *** CD-ROM | disk | FTP | other *** search
-
- Private Sub cmdDelete_Click()
-
- ' Make sure the user entered a section name.
- If txtSectionName.Text = "" Then
- MsgBox "Please enter a section name first."
- Exit Sub
- End If
- ' Check for a key name only when accessing the
- ' Registry.
- If optType(1).Value = True Then
- If txtKeyName.Text = "" Then
- MsgBox "Please enter a key name first."
- Exit Sub
- End If
- End If
-
- ' For INI files, call the INIDelete procedure. For
- ' the Registry, call the RegDelete procedure.
- If optType(0).Value = True Then
- lblStatus = INIDelete()
- Else
- lblStatus = RegDelete()
- End If
-
- End Sub
-
-
- Private Function INIDelete() As String
-
- Dim lonStatus As Long
- Dim lonYesNo As Long
- Dim strKeyName As String
- Dim strSectionName As String
-
- ' Remove brackets from section name, if necessary.
- strSectionName = FixSectionName(txtSectionName.Text)
-
- If txtKeyName.Text = "" Then
- ' No specific key name was specified, so the
- ' entire section will be deleted. Ask the user
- ' if this is okay as a safety measure.
- lonYesNo = MsgBox("Delete all keys in section?", vbYesNo)
- If lonYesNo = vbNo Then
- INIDelete = "Delete operation aborted"
- Exit Function
- End If
- ' When deleting a section, the key name passed
- ' to the API function should be vbNullString.
- strKeyName = vbNullString
- Else
- ' When deleting a specific key, the key name
- ' is passed to the API function.
- strKeyName = txtKeyName.Text
- End If
-
- ' Use the WritePrivateProfileString API function to
- ' delete specific keys or entire sections.
- lonStatus = WritePrivateProfileString(strSectionName, _
- strKeyName, vbNullString, dlgGetFilename.FileName)
-
- ' Display the status of the operation and update
- ' the file contents list box if successful.
- If lonStatus = 0 Then
- INIDelete = "Error - Key could not be deleted"
- Else
- INIDelete = "Key deleted successfully"
- txtKeyName.Text = ""
- txtValue.Text = ""
- ReadFile
- End If
-
- End Function
-