home *** CD-ROM | disk | FTP | other *** search
-
- Private Sub cmdAdd_Click()
-
- ' Make sure the user entered a section name.
- If txtSectionName.Text = "" Then
- MsgBox "Please enter a section name first."
- Exit Sub
- End If
-
- ' For INI files, call the INIAdd function. For
- ' the Registry, call the RegAdd function.
- If optType(0).Value = True Then
- lblStatus = INIAdd()
- Else
- lblStatus = RegAdd()
- End If
-
- End Sub
-
-
- Private Function INIAdd() As String
-
- Dim lonStatus As Long
- Dim strSectionName As String
-
- ' Remove brackets from section name, if necessary.
- strSectionName = FixSectionName(txtSectionName.Text)
-
- If txtKeyName.Text = "" Then
- ' No key name was specified, so add a new (empty)
- ' section with the WritePrivateProfileSection
- ' API function.
- lonStatus = WritePrivateProfileSection(strSectionName, _
- "", dlgGetFilename.FileName)
- ' Determine the status of the operation.
- If lonStatus = 0 Then
- INIAdd = "Error - Section could not be added"
- Else
- INIAdd = "Section added succesfully"
- ReadFile
- End If
- Else
- ' Use the WritePrivateProfileString API function
- ' to add the key and, if necessary, the section.
- lonStatus = WritePrivateProfileString(strSectionName, _
- txtKeyName.Text, txtValue.Text, dlgGetFilename.FileName)
- ' Determine the status of the operation.
- If lonStatus = 0 Then
- INIAdd = "Error - Key could not be added"
- Else
- INIAdd = "Key added successfully"
- ReadFile
- End If
- End If
-
- End Function
-