home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
- Begin VB.Form exam1a
- Caption = "INI Files Sample 1"
- ClientHeight = 3345
- ClientLeft = 2010
- ClientTop = 1545
- ClientWidth = 5400
- LinkTopic = "Form1"
- ScaleHeight = 3345
- ScaleWidth = 5400
- Begin VB.TextBox txtValue
- Height = 300
- Left = 1560
- TabIndex = 3
- Top = 1440
- Width = 2505
- End
- Begin VB.ComboBox comEntry
- Height = 315
- Left = 1560
- Style = 2 'Dropdown List
- TabIndex = 2
- ToolTipText = "Selection The Section You Wish to View"
- Top = 1020
- Width = 2505
- End
- Begin VB.ComboBox comSection
- Height = 315
- Left = 1560
- Style = 2 'Dropdown List
- TabIndex = 1
- ToolTipText = "Selection The Section You Wish to View"
- Top = 630
- Width = 2505
- End
- Begin MSComDlg.CommonDialog diaexam1
- Left = 660
- Top = 2760
- _ExtentX = 847
- _ExtentY = 847
- _Version = 327681
- CancelError = -1 'True
- DialogTitle = "Select File to Open"
- FileName = "*.ini"
- Filter = "Initialization file (*.ini)|*.ini"
- End
- Begin VB.CommandButton cmdSave
- Caption = "&Save"
- Height = 300
- Left = 3450
- TabIndex = 4
- Top = 2910
- Width = 700
- End
- Begin VB.CommandButton cmdSelect
- Caption = "&?"
- Height = 315
- Left = 4170
- TabIndex = 7
- Top = 240
- Width = 345
- End
- Begin VB.TextBox txtFileName
- Height = 300
- Left = 1560
- TabIndex = 0
- ToolTipText = "Enter the Path/Name of the INI file or Depress the ""?"" button to Select an INI file"
- Top = 240
- Width = 2505
- End
- Begin VB.CommandButton cmdExit
- Caption = "E&xit"
- Height = 300
- Left = 4260
- TabIndex = 5
- Top = 2910
- Width = 700
- End
- Begin VB.Label lblValue
- Alignment = 1 'Right Justify
- Caption = "Value"
- Height = 270
- Left = 270
- TabIndex = 10
- Top = 1440
- Width = 1245
- End
- Begin VB.Label lblEntryName
- Alignment = 1 'Right Justify
- Caption = "Entry Name"
- Height = 270
- Left = 240
- TabIndex = 9
- Top = 1050
- Width = 1245
- End
- Begin VB.Label lblSection
- Alignment = 1 'Right Justify
- Caption = "Section"
- Height = 270
- Left = 240
- TabIndex = 8
- Top = 660
- Width = 1245
- End
- Begin VB.Label lblIniFile
- Alignment = 1 'Right Justify
- Caption = "INI File"
- Height = 270
- Left = 240
- TabIndex = 6
- Top = 240
- Width = 1245
- End
- Attribute VB_Name = "exam1a"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Option Base 1
- Private Sub cmdSave_Click()
- Dim nbytes As Long
- nbytes = WritePrivateProfileString(comSection.Text, comEntry.Text, txtValue.Text, txtFileName.Text)
- End Sub
- Private Sub comEntry_Click()
- Dim nbytes As String
- Dim cvalue As String
- ' Initialize returned string
- ' --------------------------
- cvalue = Space$(4096)
- nbytes = GetPrivateProfileString((comSection.Text), (comEntry.Text), "", cvalue, 4096, txtFileName.Text)
- txtValue.Text = cvalue
- End Sub
- Private Sub comSection_Click()
- Dim nbytes As Long
- Dim cvalues As String * 32767
- Dim cbuffer As String
- Dim x As Integer
- Dim y As Integer
- Dim ctext As String
- Dim nend As Integer
- comEntry.Clear
- txtValue.Text = ""
- nbytes = GetPrivateProfileSection(comSection.Text, cvalues, 32767, txtFileName.Text)
- ' get all of the values
- x = 1
- y = 0
- Do While Not nend = True
- x = InStr(y + 1, cvalues, Chr(0))
- ctext = Mid$(cvalues, y + 1, x - y - 1)
- If Len(ctext) = 0 Then
- Exit Do
- End If
- '
- 'Strip off the "=" and value
- comEntry.AddItem Mid$(ctext, 1, InStr(ctext, "=") - 1)
- y = x
- End Sub
- Private Sub cmdExit_Click()
- Unload Me
- End Sub
- Private Sub cmdSelect_Click()
- Dim nbytes As Long
- Dim csection As String
- Dim cbuffer As String
- Dim cstring As String
- Dim nfirst As Integer
- On Error Resume Next
- If Len(txtFileName.Text) = 0 Then
- diaexam1.filename = ""
- diaexam1.ShowOpen
- If Err = cdlCancel Then
- ' the user depressed cancel
- Exit Sub
- End If
- txtFileName.Text = diaexam1.filename
- End If
- txtValue.Text = ""
- comSection.Clear
- If Len(txtFileName.Text) = 0 Then
- ' There has not been a file selected exit
- Exit Sub
- End If
- If Len(Dir$(txtFileName.Text)) = 0 Then
- ' invalid file name
- Exit Sub
- End If
- Open txtFileName.Text For Input As #1
- Do While EOF(1) = False
- cstring = Input$(1, #1)
- If cstring = "[" Then
- nfirst = True
- ' Drop the Bracket
- cstring = ""
-
- End If
- If cstring = "]" Then
- If nfirst = True Then
-
- If Len(csection) > 0 Then
-
- 'Add it to the selction list
- comSection.AddItem csection
- ' Drop The trailing Braket
- csection = ""
-
- End If
-
- nfirst = False
-
- End If
-
- nfirst = False
- End If
- If nfirst = True Then
-
- csection = csection & cstring
- End If
- Close #1
- comSection.ListIndex = 0
- On Error GoTo 0
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Set exam1a = Nothing
- End Sub
- Private Sub txtFileName_LostFocus()
- If Len(txtFileName.Text) > 0 Then
- cmdSelect_Click
- End If
- End Sub
-