home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap22 / ini-file.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-24  |  3.0 KB  |  75 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   8460
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6690
  8.    Height          =   8865
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   8460
  12.    ScaleWidth      =   6690
  13.    Top             =   1170
  14.    Width           =   6810
  15. Attribute VB_Name = "Form1"
  16. Attribute VB_Creatable = False
  17. Attribute VB_Exposed = False
  18. Option Explicit
  19. Private Declare Function GetProfileInt Lib "kernel32" _
  20.     Alias "GetProfileIntA" (ByVal lpAppName As String, _
  21.     ByVal lpKeyName As String, ByVal nDefault As Long) As Long
  22. Private Declare Function GetProfileString Lib "kernel32" _
  23.     Alias "GetProfileStringA" (ByVal lpAppName As String, _
  24.     ByVal lpKeyName As String, ByVal lpDefault As String, _
  25.     ByVal lpReturnedString As String, ByVal nSize As Long) As Long
  26. Private Declare Function WriteProfileString Lib "kernel32" _
  27.     Alias "WriteProfileStringA" (ByVal lpszSection As String, _
  28.     ByVal lpszKeyName As String, ByVal lpszString As String) As Long
  29. Private Declare Function GetPrivateProfileInt Lib "kernel32" _
  30.     Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
  31.     ByVal lpKeyName As String, ByVal nDefault As Long, _
  32.     ByVal lpFileName As String) As Long
  33. Private Declare Function GetPrivateProfileString Lib "kernel32" _
  34.     Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
  35.     ByVal lpKeyName As String, ByVal lpDefault As String, _
  36.     ByVal lpReturnedString As String, ByVal nSize As Long, _
  37.     ByVal lpFileName As String) As Long
  38. Private Declare Function WritePrivateProfileString Lib "kernel32" _
  39.     Alias "WritePrivateProfileStringA" _
  40.     (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
  41.     ByVal lpString As String, ByVal lpFileName As String) As Long
  42. Dim secName As String
  43. Dim keyName As String
  44. Dim prvName As String
  45. Private Sub Form_Load()
  46.     Dim keyValue As String
  47.     secName = "VB Unleashed"
  48.     keyName = "Chapter Number"
  49.     prvName = "sams.ini"
  50.     keyValue = "22-Using the Windows 95 APIs"
  51.     testPrivateProfile
  52.     WritePrivateProfileString secName, keyName, keyValue, prvName
  53.     testPrivateProfile
  54.     WritePrivateProfileString secName, keyName, "", prvName
  55.     testPrivateProfile
  56. End Sub
  57. Private Sub testProfile()
  58.     Dim lChapNum As Long
  59.     Dim sChapNum As String
  60.     lChapNum = GetProfileInt(secName, keyName, 10)
  61.     sChapNum = Space(50)
  62.     GetProfileString secName, keyName, "10", sChapNum, Len(sChapNum)
  63.     MsgBox "Chapter Int = " & lChapNum
  64.     MsgBox "Chapter Str = " & sChapNum
  65. End Sub
  66. Private Sub testPrivateProfile()
  67.     Dim lChapNum As Long
  68.     Dim sChapNum As String
  69.     lChapNum = GetPrivateProfileInt(secName, keyName, 10, prvName)
  70.     sChapNum = Space(50)
  71.     GetPrivateProfileString secName, keyName, "10", sChapNum, Len(sChapNum), prvName
  72.     MsgBox "Private Chapter Int = " & lChapNum
  73.     MsgBox "Private Chapter Str = " & sChapNum
  74. End Sub
  75.