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

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2775
  5.    ClientLeft      =   3165
  6.    ClientTop       =   3810
  7.    ClientWidth     =   6690
  8.    Height          =   3180
  9.    Left            =   3105
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2775
  12.    ScaleWidth      =   6690
  13.    Top             =   3465
  14.    Width           =   6810
  15.    Begin VB.TextBox Text2 
  16.       Height          =   495
  17.       Left            =   2160
  18.       TabIndex        =   3
  19.       Text            =   "Text2"
  20.       Top             =   2160
  21.       Width           =   3375
  22.    End
  23.    Begin VB.TextBox Text1 
  24.       Height          =   495
  25.       Left            =   2160
  26.       TabIndex        =   2
  27.       Text            =   "Text1"
  28.       Top             =   1440
  29.       Width           =   3495
  30.    End
  31.    Begin VB.CommandButton Command2 
  32.       Caption         =   "Command2"
  33.       Height          =   495
  34.       Left            =   120
  35.       TabIndex        =   1
  36.       Top             =   720
  37.       Width           =   1215
  38.    End
  39.    Begin VB.CommandButton Command1 
  40.       Caption         =   "Command1"
  41.       Height          =   495
  42.       Left            =   120
  43.       TabIndex        =   0
  44.       Top             =   120
  45.       Width           =   1215
  46.    End
  47.    Begin VB.Label Label1 
  48.       Caption         =   "Name"
  49.       Height          =   495
  50.       Left            =   720
  51.       TabIndex        =   5
  52.       Top             =   2160
  53.       Width           =   1215
  54.    End
  55.    Begin VB.Label ID 
  56.       Caption         =   "ID Number"
  57.       Height          =   375
  58.       Left            =   720
  59.       TabIndex        =   4
  60.       Top             =   1440
  61.       Width           =   1215
  62.    End
  63. Attribute VB_Name = "Form1"
  64. Attribute VB_Creatable = False
  65. Attribute VB_Exposed = False
  66. Option Explicit
  67. Private Type Record
  68.     ID As String * 3
  69.     Name As String * 20
  70. End Type
  71. Dim MyRecord As Record
  72. Dim recIdx As Long
  73. Dim recBuf As String * 100
  74. Dim F As New COMPRESSION
  75. Private Sub Command1_Click()
  76.     Dim idx As Long
  77.     F.fileName = "testfile.dat"
  78.     Open F.fileName For Random As #1 Len = Len(MyRecord)
  79.     For idx = 0 To 25
  80.         MyRecord.ID = CStr(idx) + 1
  81.         MyRecord.Name = "*" & String(18, idx + Asc("A")) & "*"
  82.         Put #1, , MyRecord
  83.     Next idx
  84.     Close #1
  85.     F.compress
  86.     MsgBox "textfile.dat has been compressed...Go Look! Then click OK."
  87.     Kill "testfile.dat"
  88.     MsgBox "testfile.dat has been deleted...Go Look! Then click OK."
  89.     F.expand
  90.     MsgBox "textfile.da_ has been expanded...Go Look! Then click OK."
  91.     Command1.Enabled = False
  92.     Command2.Enabled = True
  93.     readRec
  94. End Sub
  95. Private Sub Command2_Click()
  96.     If recIdx > 26 Then recIdx = 1
  97.     readRec
  98. End Sub
  99. Private Sub Form_Load()
  100.     Command1.Caption = "Create TestFile"
  101.     Command2.Caption = "Next Record"
  102.     Command2.Enabled = False
  103.     recIdx = 1
  104. End Sub
  105. Private Sub readRec()
  106.     F.read recIdx, Len(MyRecord), recBuf
  107.     MyRecord.ID = Left(recBuf, 3)
  108.     MyRecord.Name = Mid(recBuf, 4)
  109.     Text1.TEXT = MyRecord.ID
  110.     Text2.TEXT = MyRecord.Name
  111.     recIdx = recIdx + 1
  112. End Sub
  113.