home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dbase64w / dbase64w.exe / dBase64.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-11  |  5.4 KB  |  172 lines

  1. VERSION 5.00
  2. Object = "{9D23596C-B861-11D2-A020-00C04F72D7D2}#1.0#0"; "dBase64.dll"
  3. Begin VB.Form Form1 
  4.    Caption         =   "DameWare Base64 Encoder/Decoder Sample"
  5.    ClientHeight    =   3960
  6.    ClientLeft      =   60
  7.    ClientTop       =   348
  8.    ClientWidth     =   5988
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   3960
  11.    ScaleWidth      =   5988
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.CommandButton Command3 
  14.       Caption         =   "Binary File"
  15.       Height          =   372
  16.       Left            =   4800
  17.       TabIndex        =   9
  18.       Top             =   1920
  19.       Width           =   1092
  20.    End
  21.    Begin VB.TextBox Text1 
  22.       Height          =   855
  23.       Left            =   0
  24.       MultiLine       =   -1  'True
  25.       TabIndex        =   0
  26.       Text            =   "dBase64.frx":0000
  27.       Top             =   480
  28.       Width           =   4575
  29.    End
  30.    Begin VB.CommandButton Command1 
  31.       Caption         =   "Encode"
  32.       Default         =   -1  'True
  33.       Height          =   375
  34.       Left            =   4800
  35.       TabIndex        =   1
  36.       Top             =   720
  37.       Width           =   1095
  38.    End
  39.    Begin VB.TextBox Text2 
  40.       Height          =   855
  41.       Left            =   0
  42.       MultiLine       =   -1  'True
  43.       TabIndex        =   3
  44.       Top             =   1680
  45.       Width           =   4575
  46.    End
  47.    Begin VB.TextBox Text3 
  48.       Height          =   855
  49.       Left            =   0
  50.       MultiLine       =   -1  'True
  51.       TabIndex        =   4
  52.       Top             =   3000
  53.       Width           =   4575
  54.    End
  55.    Begin VB.CommandButton Command2 
  56.       Caption         =   "Decode"
  57.       Height          =   375
  58.       Left            =   4800
  59.       TabIndex        =   2
  60.       Top             =   1320
  61.       Width           =   1095
  62.    End
  63.    Begin DBASE64LibCtl.Base64Ctl Base64Ctl1 
  64.       Height          =   480
  65.       Left            =   5160
  66.       TabIndex        =   8
  67.       Top             =   120
  68.       Width           =   480
  69.       _cx             =   4588367
  70.       _cy             =   4588367
  71.       EncodedString   =   ""
  72.       DecodedString   =   ""
  73.    End
  74.    Begin VB.Label Label1 
  75.       Caption         =   "Text to Encode"
  76.       Height          =   255
  77.       Left            =   0
  78.       TabIndex        =   7
  79.       Top             =   240
  80.       Width           =   1935
  81.    End
  82.    Begin VB.Label Label2 
  83.       Caption         =   "Encoded Result "
  84.       Height          =   255
  85.       Left            =   0
  86.       TabIndex        =   6
  87.       Top             =   1440
  88.       Width           =   1935
  89.    End
  90.    Begin VB.Label Label3 
  91.       Caption         =   "Decoded Result "
  92.       Height          =   255
  93.       Left            =   0
  94.       TabIndex        =   5
  95.       Top             =   2760
  96.       Width           =   1935
  97.    End
  98. Attribute VB_Name = "Form1"
  99. Attribute VB_GlobalNameSpace = False
  100. Attribute VB_Creatable = False
  101. Attribute VB_PredeclaredId = True
  102. Attribute VB_Exposed = False
  103. Private Sub Command1_Click()
  104.     Text2.Text = ""
  105.     Text2.Refresh
  106.     Base64Ctl1.DecodedString = Text1.Text
  107.     Base64Ctl1.Encode
  108.     Text2.Text = Base64Ctl1.EncodedString
  109. End Sub
  110. Private Sub Command2_Click()
  111.     Text3.Text = ""
  112.     Text3.Refresh
  113.     Base64Ctl1.EncodedString = Text2.Text
  114.     Base64Ctl1.Decode
  115.     Text3.Text = Base64Ctl1.DecodedString
  116. End Sub
  117. Private Sub Command3_Click()
  118. On Error GoTo errorlogic
  119. Dim Msg As String
  120. Dim MyBinFile, MyBinFileEncoded, MyBinFileDecoded As String
  121. MyBinFile = InputBox("Enter binary file to encode/decode: ", , "c:\Program Files\DameWare\dBase64\testbin.doc")
  122. If MyBinFile <> "" Then ' user pressed Cancel...
  123.     MyBinFile = Dir(MyBinFile)
  124.     If MyBinFile <> "" Then
  125.        TheDecimalPosition = InStr(1, MyBinFile, ".")
  126.        TheFileExtent = Mid(MyBinFile, TheDecimalPosition + 1, 3)
  127.        MyBinFileEncoded = Mid(MyBinFile, 1, TheDecimalPosition - 1) & "e.txt"
  128.        MyBinFileDecoded = Mid(MyBinFile, 1, TheDecimalPosition - 1) & "d." & _
  129.             TheFileExtent
  130.        
  131.        Open MyBinFile For Binary As #1
  132.     ' Set Msg equal to # of chars as the file
  133.        Msg = String(FileLen(MyBinFile), " ")
  134.     ' Read the file into Msg
  135.        Get #1, , Msg
  136.        
  137.     ' Encode the string
  138.        Base64Ctl1.DecodedString = Msg
  139.        Base64Ctl1.Encode
  140.        Msg = Base64Ctl1.EncodedString
  141.         
  142.        Close #1
  143.          
  144.        Open MyBinFileEncoded For Binary As #1
  145.        Put #1, , Msg ' write out encoded "e" file.
  146.        Close #1
  147.             
  148.     ' Decode the string
  149.        Base64Ctl1.EncodedString = Msg
  150.        Base64Ctl1.Decode
  151.        
  152.        Open MyBinFileDecoded For Binary As #1
  153.        Put #1, , Base64Ctl1.DecodedString ' write out decoded "d" file.
  154.        Close #1
  155.         
  156.        MsgBox "The resulting encoded binary file is: " & MyBinFileEncoded & Chr(13) & Chr(10) & CrLf & _
  157.               "The resulting decoded binary file is: " & MyBinFileDecoded
  158.     Else
  159.         MsgBox ("File not found")
  160.     End If
  161. End If
  162. errorlogic:
  163. If Err.Number <> 0 Then
  164.     Msg = "Error # " & Str(Err.Number) & " was generated by " _
  165.             & Err.Source & Chr(13) & Err.Description
  166.     MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
  167. End If
  168. End Sub
  169. Private Sub Form_Load()
  170.     Text1.Text = "This is a sample string used to demonstrate the Base64 Encoding and Decoding."
  171. End Sub
  172.