home *** CD-ROM | disk | FTP | other *** search
-
- Private Sub cmdRetrieve_Click()
-
- Dim lonOpStatus As Long
-
- ' Make sure both a key name and a section name
- ' have been specified by the user.
- If txtSectionName.Text = "" Then
- MsgBox "Please enter a section name first."
- Exit Sub
- End If
- If txtKeyName.Text = "" Then
- MsgBox "Please enter a key name first."
- Exit Sub
- End If
-
- ' For INI files, call the INIRetrieve function. For
- ' the Registry, call the RegRetrieve function.
- If optType(0).Value = True Then
- lblStatus = INIRetrieve()
- Else
- lblStatus = RegRetrieve()
- End If
-
- End Sub
-
-
- Private Function INIRetrieve() As String
-
- Dim lonValueSize As Long
- Dim strSectionName As String
-
- ' Remove brackets from section name, if necessary.
- strSectionName = FixSectionName(txtSectionName.Text)
-
- ' Use the GetPrivateProfileString API function to
- ' retrieve the key's value from the file. A default
- ' value of "?!?" is used to see if the key has been
- ' retrieved successfully.
- lonValueSize = GetPrivateProfileString(strSectionName, _
- txtKeyName.Text, "?!?", gstrKeyValue, 256, _
- dlgGetFilename.FileName)
-
- ' Determine the status of the operation. If the
- ' value of the key is the same as the default value
- ' ("?!?"), then the key was probably not found.
- If Left$(gstrKeyValue, 3) = "?!?" Then
- INIRetrieve = "Error - Key could not be located"
- Else
- INIRetrieve = "Key retrieved successfully"
- txtValue.Text = Left$(gstrKeyValue, lonValueSize)
- End If
-
- End Function
-