home *** CD-ROM | disk | FTP | other *** search
/ Software Recommendations - 1998 Season 1 / DNBCD4.iso / develop / lib / addzip / ADDZIP.ZIP / TESTAIM / TESTAIM.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-06-01  |  6.4 KB  |  175 lines

  1. VERSION 2.00
  2. Begin Form frmTest 
  3.    BackColor       =   &H00800000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Test AIM"
  6.    ClientHeight    =   5580
  7.    ClientLeft      =   1065
  8.    ClientTop       =   1485
  9.    ClientWidth     =   6615
  10.    Height          =   5985
  11.    Left            =   1005
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   5580
  15.    ScaleWidth      =   6615
  16.    Top             =   1140
  17.    Width           =   6735
  18.    Begin TextBox txtDecompressed 
  19.       Enabled         =   0   'False
  20.       Height          =   1095
  21.       Left            =   240
  22.       MultiLine       =   -1  'True
  23.       TabIndex        =   2
  24.       Text            =   "Text1"
  25.       Top             =   4200
  26.       Width           =   6135
  27.    End
  28.    Begin TextBox txtCompressed 
  29.       Enabled         =   0   'False
  30.       Height          =   1095
  31.       Left            =   240
  32.       MultiLine       =   -1  'True
  33.       TabIndex        =   6
  34.       Text            =   "Text1"
  35.       Top             =   2280
  36.       Width           =   6135
  37.    End
  38.    Begin CommandButton cmdDecompress 
  39.       Enabled         =   0   'False
  40.       Height          =   375
  41.       Left            =   240
  42.       TabIndex        =   5
  43.       Top             =   3480
  44.       Width           =   6135
  45.    End
  46.    Begin CommandButton cmdCompress 
  47.       Height          =   375
  48.       Left            =   240
  49.       TabIndex        =   1
  50.       Top             =   1560
  51.       Width           =   6135
  52.    End
  53.    Begin TextBox txtOriginal 
  54.       Height          =   1095
  55.       Left            =   240
  56.       MultiLine       =   -1  'True
  57.       ScrollBars      =   2  'Vertical
  58.       TabIndex        =   0
  59.       Top             =   360
  60.       Width           =   6135
  61.    End
  62.    Begin Label Label4 
  63.       BackStyle       =   0  'Transparent
  64.       Caption         =   "Decompressed buffer:"
  65.       ForeColor       =   &H00FFFFFF&
  66.       Height          =   255
  67.       Left            =   240
  68.       TabIndex        =   7
  69.       Top             =   3960
  70.       Width           =   6135
  71.    End
  72.    Begin Label Label2 
  73.       BackStyle       =   0  'Transparent
  74.       Caption         =   "Compressed buffer:"
  75.       ForeColor       =   &H00FFFFFF&
  76.       Height          =   255
  77.       Left            =   240
  78.       TabIndex        =   4
  79.       Top             =   2040
  80.       Width           =   6135
  81.    End
  82.    Begin Label Label1 
  83.       BackStyle       =   0  'Transparent
  84.       Caption         =   "Original buffer:"
  85.       ForeColor       =   &H00FFFFFF&
  86.       Height          =   255
  87.       Left            =   240
  88.       TabIndex        =   3
  89.       Top             =   120
  90.       Width           =   4215
  91.    End
  92. ' testaim.frm
  93. ' Visual Basic v3 testbed for aim16.dll
  94. Option Explicit
  95. ' save the size of the original string (so we can
  96. ' allocate the correct sized buffer)
  97. Dim g_lOriginalSize As Long
  98. ' save the compressed string
  99. Dim g_cCompressed As String
  100. ' save the compressed size
  101. Dim g_cCompressedSize As Long
  102. Sub cmdCompress_Click ()
  103.     Dim cOriginal As String ' original string
  104.     Dim cBuffer As String ' buffer for compressed string
  105.     Dim lOriginal As Long ' length of the original string
  106.     Dim lBuffer As Long ' length of the compression buffer
  107.     Dim lCompressedSize ' length of the compressed string (or an error)
  108.     ' set length of original string
  109.     lOriginal = Len(txtOriginal.Text)
  110.     ' get the original string
  111.     cOriginal = txtOriginal.Text
  112.     label1.Caption = "Original buffer: " & Format$(lOriginal) & " characters"
  113.     'set length of compressed buffer (which should be larger
  114.     ' than the original buffer by 1% + 12 bytes)
  115.     lBuffer = 12 + (lOriginal * 101) / 100
  116.     ' allocate empty compression buffer
  117.     cBuffer = Space(lBuffer)
  118.     ' call compression function
  119.     lCompressedSize = addZIP_InMemory(cOriginal, lOriginal, cBuffer, lBuffer)
  120.     If (lCompressedSize < 0) Then ' an error has occured
  121.         txtCompressed.Text = "COMPRESSION FAILED!! Error code " & Format$(lCompressedSize)
  122.         Exit Sub
  123.     End If
  124.     ' if we get to here then no error has occurred
  125.     '
  126.     ' save the original size for later decompression
  127.     g_lOriginalSize = lOriginal
  128.     g_cCompressed = Left$(cBuffer, lCompressedSize)
  129.     g_cCompressedSize = lCompressedSize
  130.     ' enable the decompression button
  131.     cmdDecompress.Enabled = True
  132.     ' display the compressed string
  133.     txtCompressed.Text = Left$(cBuffer, lCompressedSize)
  134.     ' display the size of the compressed string
  135.     label2.Caption = "Compressed buffer: " & Format$(lCompressedSize) & " characters"
  136. End Sub
  137. Sub cmdDecompress_Click ()
  138.     Dim cOriginal As String ' original string
  139.     Dim cBuffer As String ' buffer for compressed string
  140.     Dim lOriginal As Long ' length of the original string
  141.     Dim lBuffer As Long ' length of the compression buffer
  142.     Dim lCompressedSize ' length of the compressed string (or an error)
  143.     ' set length of original string (with extra space
  144.     ' which shouldnt be required)
  145.     lOriginal = g_lOriginalSize + 10
  146.     ' allocate the empty string for the original
  147.     cOriginal = Space$(lOriginal)
  148.     ' set length of the compressed string from global
  149.     lBuffer = g_cCompressedSize
  150.     ' set compressed string from global
  151.     cBuffer = g_cCompressed
  152.     ' call decompression function
  153.     lOriginal = addUNZIP_InMemory(cOriginal, lOriginal, cBuffer, lBuffer)
  154.     ' check for errors
  155.     If (lOriginal < 0) Then ' an error has occured
  156.         txtDecompressed.Text = "DECOMPRESSION FAILED!! Error code " & Format$(lCompressedSize)
  157.         Exit Sub
  158.     End If
  159.     ' if we get to here, no error occurred
  160.     '
  161.     ' display decompressed string
  162.     txtDecompressed.Text = Left$(cOriginal, lOriginal)
  163.     label4.Caption = "Decompressed buffer: " & Format$(lOriginal) & " characters"
  164. End Sub
  165. Sub Form_Load ()
  166.     txtOriginal.Text = "Type some text here and press the button below to compress it. "
  167.     txtOriginal.Text = txtOriginal.Text & Chr$(13) & Chr$(10) & txtOriginal.Text
  168.     txtOriginal.Text = txtOriginal.Text & Chr$(13) & Chr$(10) & txtOriginal.Text
  169.     cmdCompress.Caption = "Press me to compress"
  170.     txtCompressed.Text = "The compressed string will be placed here"
  171.     cmdDecompress.Caption = "Press me to decompress"
  172.     ' centre me on the screen
  173.     Move screen.Width / 2 - Me.Width / 2, screen.Height / 2 - Me.Height / 2
  174. End Sub
  175.