home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / base641a / form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-20  |  2.8 KB  |  81 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Base64"
  5.    ClientHeight    =   780
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   2040
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   780
  13.    ScaleWidth      =   2040
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton Command1 
  17.       Caption         =   "Test Speed"
  18.       Height          =   675
  19.       Left            =   60
  20.       TabIndex        =   0
  21.       Top             =   60
  22.       Width           =   1935
  23.    End
  24. Attribute VB_Name = "Form1"
  25. Attribute VB_GlobalNameSpace = False
  26. Attribute VB_Creatable = False
  27. Attribute VB_PredeclaredId = True
  28. Attribute VB_Exposed = False
  29. Dim Base64 As New Encoding
  30. Private Declare Function GetTickCount Lib "kernel32" () As Long
  31. Private Sub Command1_Click()
  32. 'COMPILE THIS TO AN NATIVE-EXE FOR BEST PERFORMANCE
  33. 'THE VB IDE IS MORE THAN 10 TIMES SLOWER THAN
  34. 'A COMPILED EXECUTABLE
  35. Dim TempArray() As Byte
  36. Dim Encoded() As Byte
  37. Dim Elapsed As Single
  38. Dim EncodingRate As Single
  39. Dim Message As String
  40. Base64.Str2ByteArray String(1000000, "A"), TempArray 'encode a 1 megabyte string full of A's
  41. Elapsed = GetTickCount
  42. Base64.EncodeB64 TempArray, Encoded
  43. 'Encoded() now contains the encoded byte array
  44. 'to convert it to a string use:
  45. 'a = StrConv(Encoded, vbUnicode)
  46. 'a will now have the decoded string
  47. 'IMPORTANT NOTE: If you plan to use this in a
  48. 'email program, you should use the Span() function
  49. 'so the encoded string will have a maximum of 74 chars
  50. 'per line.
  51. 'Base64.Span 74, Encoded, TempArray
  52. ' - Encoded is the encoded byte array
  53. ' - TempArray is an array that will contain the result
  54. 'This function is not fully beta-tested, so be careful
  55. 'with it
  56. EncodingRate = GetTickCount - Elapsed
  57. EncodingRate = Round(1000 / EncodingRate, 2)
  58. Message = "On your current system you will get " & EncodingRate & "Mb/sec at encoding." & vbCrLf
  59. Elapsed = GetTickCount
  60. 'If Encoded() was previously Spanned with base64.span()
  61. 'you should unspan it like so:
  62. 'Base64.Unspan Encoded, TempArray
  63. 'TempArray() will now contain an unspanned string,
  64. 'ready for decoding
  65. 'NOTE:
  66. 'This function is not fully beta-tested, so be careful
  67. 'with it
  68. Base64.DecodeB64 Encoded, TempArray
  69. 'TempArray() now contains the decoded byte array
  70. 'to convert it to a string use:
  71. 'a = StrConv(TempArray, vbUnicode)
  72. 'a will now have the decoded string
  73. EncodingRate = GetTickCount - Elapsed
  74. EncodingRate = Round(1000 / EncodingRate, 2)
  75. Message = Message & "On your current system you will get " & EncodingRate & "Mb/sec at decoding."
  76. MsgBox Message, vbInformation
  77. End Sub
  78. Private Sub Form_Load()
  79. Base64.Class_Initialize
  80. End Sub
  81.