home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / Code / ch45 / chp531a.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-07-04  |  6.7 KB  |  233 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmChp531a 
  4.    Caption         =   "Chapter 53 Sample 1"
  5.    ClientHeight    =   3345
  6.    ClientLeft      =   2010
  7.    ClientTop       =   1545
  8.    ClientWidth     =   5400
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3345
  11.    ScaleWidth      =   5400
  12.    Begin VB.TextBox txtValue 
  13.       Height          =   300
  14.       Left            =   1560
  15.       TabIndex        =   3
  16.       Top             =   1440
  17.       Width           =   2505
  18.    End
  19.    Begin VB.ComboBox comEntry 
  20.       Height          =   315
  21.       Left            =   1560
  22.       Style           =   2  'Dropdown List
  23.       TabIndex        =   2
  24.       ToolTipText     =   "Selection The Section You Wish to View"
  25.       Top             =   1020
  26.       Width           =   2505
  27.    End
  28.    Begin VB.ComboBox comSection 
  29.       Height          =   315
  30.       Left            =   1560
  31.       Style           =   2  'Dropdown List
  32.       TabIndex        =   1
  33.       ToolTipText     =   "Selection The Section You Wish to View"
  34.       Top             =   630
  35.       Width           =   2505
  36.    End
  37.    Begin MSComDlg.CommonDialog diachp531 
  38.       Left            =   660
  39.       Top             =   2760
  40.       _ExtentX        =   847
  41.       _ExtentY        =   847
  42.       _Version        =   327680
  43.       CancelError     =   -1  'True
  44.       DialogTitle     =   "Select File to Open"
  45.       FileName        =   "*.ini"
  46.       Filter          =   "Initialization file (*.ini)|*.ini"
  47.    End
  48.    Begin VB.CommandButton cmdSave 
  49.       Caption         =   "&Save"
  50.       Height          =   300
  51.       Left            =   3450
  52.       TabIndex        =   4
  53.       Top             =   2910
  54.       Width           =   700
  55.    End
  56.    Begin VB.CommandButton cmdSelect 
  57.       Caption         =   "&?"
  58.       Height          =   315
  59.       Left            =   4170
  60.       TabIndex        =   7
  61.       Top             =   240
  62.       Width           =   345
  63.    End
  64.    Begin VB.TextBox txtFileName 
  65.       Height          =   300
  66.       Left            =   1560
  67.       TabIndex        =   0
  68.       ToolTipText     =   "Enter the Path/Name of the INI file or Depress the ""?"" button to Select an INI file"
  69.       Top             =   240
  70.       Width           =   2505
  71.    End
  72.    Begin VB.CommandButton cmdExit 
  73.       Caption         =   "E&xit"
  74.       Height          =   300
  75.       Left            =   4260
  76.       TabIndex        =   5
  77.       Top             =   2910
  78.       Width           =   700
  79.    End
  80.    Begin VB.Label lblValue 
  81.       Alignment       =   1  'Right Justify
  82.       Caption         =   "Value"
  83.       Height          =   270
  84.       Left            =   270
  85.       TabIndex        =   10
  86.       Top             =   1440
  87.       Width           =   1245
  88.    End
  89.    Begin VB.Label lblEntryName 
  90.       Alignment       =   1  'Right Justify
  91.       Caption         =   "Entry Name"
  92.       Height          =   270
  93.       Left            =   240
  94.       TabIndex        =   9
  95.       Top             =   1050
  96.       Width           =   1245
  97.    End
  98.    Begin VB.Label lblSection 
  99.       Alignment       =   1  'Right Justify
  100.       Caption         =   "Section"
  101.       Height          =   270
  102.       Left            =   240
  103.       TabIndex        =   8
  104.       Top             =   660
  105.       Width           =   1245
  106.    End
  107.    Begin VB.Label lblIniFile 
  108.       Alignment       =   1  'Right Justify
  109.       Caption         =   "INI File"
  110.       Height          =   270
  111.       Left            =   240
  112.       TabIndex        =   6
  113.       Top             =   240
  114.       Width           =   1245
  115.    End
  116. Attribute VB_Name = "frmChp531a"
  117. Attribute VB_GlobalNameSpace = False
  118. Attribute VB_Creatable = False
  119. Attribute VB_PredeclaredId = True
  120. Attribute VB_Exposed = False
  121. Option Explicit
  122. Option Base 1
  123. Private Sub cmdSave_Click()
  124. Dim nbytes As Long
  125. nbytes = WritePrivateProfileString(comSection.Text, comEntry.Text, txtValue.Text, txtFileName.Text)
  126. End Sub
  127. Private Sub comEntry_Click()
  128. Dim nbytes As String
  129. Dim cvalue  As String
  130. ' Initialize returned string
  131. ' --------------------------
  132. cvalue = Space$(4096)
  133. nbytes = GetPrivateProfileString((comSection.Text), (comEntry.Text), "", cvalue, 4096, txtFileName.Text)
  134. txtValue.Text = cvalue
  135. End Sub
  136. Private Sub comSection_Click()
  137. Dim nbytes As Long
  138. Dim cvalues As String * 32767
  139. Dim cbuffer As String
  140. Dim x As Integer
  141. Dim y As Integer
  142. Dim ctext As String
  143. Dim nend As Integer
  144. comEntry.Clear
  145. txtValue.Text = ""
  146. nbytes = GetPrivateProfileSection(comSection.Text, cvalues, 32767, txtFileName.Text)
  147. ' get all of the values
  148. x = 1
  149. y = 0
  150. Do While Not nend = True
  151.     x = InStr(y + 1, cvalues, Chr(0))
  152.     ctext = Mid$(cvalues, y + 1, x - y - 1)
  153.     If Len(ctext) = 0 Then
  154.         Exit Do
  155.     End If
  156.     '
  157.     'Strip off the "=" and value
  158.     comEntry.AddItem Mid$(ctext, 1, InStr(ctext, "=") - 1)
  159.     y = x
  160. End Sub
  161. Private Sub cmdExit_Click()
  162. Unload Me
  163. End Sub
  164. Private Sub cmdSelect_Click()
  165. Dim nbytes As Long
  166. Dim csection As String
  167. Dim cbuffer As String
  168. Dim cstring As String
  169. Dim nfirst As Integer
  170. On Error Resume Next
  171. If Len(txtFileName.Text) = 0 Then
  172.     diachp531.filename = ""
  173.     diachp531.ShowOpen
  174.     If Err = cdlCancel Then
  175.         ' the user depressed cancel
  176.         Exit Sub
  177.     End If
  178.     txtFileName.Text = diachp531.filename
  179. End If
  180. txtValue.Text = ""
  181. comSection.Clear
  182. If Len(txtFileName.Text) = 0 Then
  183. ' There has not been a file selected exit
  184.     Exit Sub
  185. End If
  186. If Len(Dir$(txtFileName.Text)) = 0 Then
  187. ' invalid file name
  188.     Exit Sub
  189. End If
  190. Open txtFileName.Text For Input As #1
  191. Do While EOF(1) = False
  192.     cstring = Input$(1, #1)
  193.     If cstring = "[" Then
  194.         nfirst = True
  195.         ' Drop the Bracket
  196.         cstring = ""
  197.         
  198.     End If
  199.     If cstring = "]" Then
  200.         If nfirst = True Then
  201.            
  202.            If Len(csection) > 0 Then
  203.                 
  204.                 'Add it to the selction list
  205.                 comSection.AddItem csection
  206.                 ' Drop The trailing Braket
  207.                 csection = ""
  208.                 
  209.             End If
  210.             
  211.             nfirst = False
  212.             
  213.         End If
  214.             
  215.        nfirst = False
  216.     End If
  217.     If nfirst = True Then
  218.         
  219.         csection = csection & cstring
  220.     End If
  221. Close #1
  222. comSection.ListIndex = 0
  223. On Error GoTo 0
  224. End Sub
  225. Private Sub Form_Unload(Cancel As Integer)
  226. Set frmChp531a = Nothing
  227. End Sub
  228. Private Sub txtFileName_LostFocus()
  229. If Len(txtFileName.Text) > 0 Then
  230.     cmdSelect_Click
  231. End If
  232. End Sub
  233.