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 / 309X3209.TXT < prev    next >
Encoding:
Text File  |  1998-05-05  |  1.1 KB  |  39 lines

  1.  
  2. Private Sub lstFileContents_Click()
  3.  
  4. Dim intEqualPos As Integer
  5. Dim lonListPtr As Long
  6. Dim strListItem As String
  7.  
  8. txtKeyName.Text = ""
  9. txtValue.Text = ""
  10.  
  11. ' Get the item that was chosen from the list box.
  12. strListItem = lstFileContents.List(lstFileContents.ListIndex)
  13.  
  14. ' Did the user click on a section name (enclosed in
  15. ' brackets) or a key name?
  16. If Left$(LTrim$(strListItem), 1) = "[" Then
  17.     txtSectionName.Text = strListItem
  18. Else
  19.     txtSectionName.Text = ""
  20.     ' Separate the key info into the key name and
  21.     ' its value.
  22.     intEqualPos = InStr(strListItem, "=")
  23.     If intEqualPos > 1 Then
  24.         txtKeyName.Text = Left$(strListItem, intEqualPos - 1)
  25.         txtValue.Text = Mid$(strListItem, intEqualPos + 1)
  26.     End If
  27.     ' Loop backwards through the list and try to
  28.     ' find the section name to which the key belongs.
  29.     For lonListPtr = lstFileContents.ListIndex To 0 Step -1
  30.         strListItem = LTrim$(lstFileContents.List(lonListPtr))
  31.         If Left$(strListItem, 1) = "[" Then
  32.             txtSectionName.Text = strListItem
  33.             Exit For
  34.         End If
  35.     Next lonListPtr
  36. End If
  37.  
  38. End Sub
  39.