home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / mastvb6.exe / FileIO / FILEIO / FileIO.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-07-13  |  3.8 KB  |  120 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form FILEIOForm 
  4.    Caption         =   "File I/O Demo"
  5.    ClientHeight    =   2355
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4410
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   2355
  11.    ScaleWidth      =   4410
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.CommandButton Command2 
  14.       Caption         =   "Process Binary File"
  15.       Height          =   495
  16.       Left            =   120
  17.       TabIndex        =   1
  18.       Top             =   840
  19.       Width           =   1815
  20.    End
  21.    Begin MSComDlg.CommonDialog CommonDialog1 
  22.       Left            =   1440
  23.       Top             =   1560
  24.       _ExtentX        =   847
  25.       _ExtentY        =   847
  26.       _Version        =   393216
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "Process Text File"
  30.       Height          =   495
  31.       Left            =   120
  32.       TabIndex        =   0
  33.       Top             =   240
  34.       Width           =   1815
  35.    End
  36. Attribute VB_Name = "FILEIOForm"
  37. Attribute VB_GlobalNameSpace = False
  38. Attribute VB_Creatable = False
  39. Attribute VB_PredeclaredId = True
  40. Attribute VB_Exposed = False
  41. Private Sub Command1_Click()
  42. Dim infile As String, outfile As String
  43. Dim infileNumber As Integer, outfileNumber As Integer
  44. Dim tline As String
  45. Dim outline As String
  46.     CommonDialog1.FileName = ""
  47.     CommonDialog1.Filter = "Text Files|*.TXT"
  48.     CommonDialog1.ShowOpen
  49.     infile = CommonDialog1.FileName
  50.     If infile = "" Then Exit Sub
  51. GetOutFileName:
  52.     CommonDialog1.FileName = ""
  53.     CommonDialog1.ShowSave
  54.     outfile = CommonDialog1.FileName
  55.     If outfile = "" Then Exit Sub
  56.     If infile = outfile Then
  57.         MsgBox "This application will not overwrite the source file." & vbCrLf & _
  58.                "Please select another output file name"
  59.         GoTo GetOutFileName
  60.     End If
  61.     infileNumber = FreeFile
  62.     Open infile For Input Access Read As #infileNumber
  63.     outfileNumber = FreeFile
  64.     Open outfile For Output Access Write As #outfileNumber
  65.     While Not EOF(infileNumber)
  66.         Line Input #infileNumber, tline
  67.         outline = Process(tline)
  68.         Print #outfileNumber, outline
  69.     Wend
  70.     Close infileNumber
  71.     Close outfileNumber
  72. End Sub
  73. Function Process(txt) As String
  74.     Process = UCase(txt)
  75. End Function
  76. Private Sub Command2_Click()
  77. Dim infile As String, outfile As String
  78. Dim infileNumber As Integer, outfileNumber As Integer
  79. Dim tline As String
  80. Dim outline As String
  81.     CommonDialog1.FileName = ""
  82.     CommonDialog1.Filter = "All Files|*.*"
  83.     CommonDialog1.ShowOpen
  84.     infile = CommonDialog1.FileName
  85.     If infile = "" Then Exit Sub
  86. GetOutFileName:
  87.     CommonDialog1.FileName = ""
  88.     CommonDialog1.ShowSave
  89.     outfile = CommonDialog1.FileName
  90.     If outfile = "" Then Exit Sub
  91.     If infile = outfile Then
  92.         MsgBox "This application will not overwrite the source file." & vbCrLf & _
  93.                "Please select another output file name"
  94.         GoTo GetOutFileName
  95.     End If
  96.     infileNumber = FreeFile
  97.     Open infile For Binary Access Read As #infileNumber
  98.     outfileNumber = FreeFile
  99.     Open outfile For Binary Access Write As #outfileNumber
  100. Dim inChar As Byte, outChar As Byte
  101. Dim startTime As Date
  102. Dim ipos As Long
  103.     startTime = Now
  104.     i = 0
  105.     FLen = LOF(infileNumber)
  106.     While Not EOF(infileNumber)
  107.         Get #infileNumber, , inChar
  108.         outChar = inChar
  109.         Put #outfileNumber, , outChar
  110.         ipos = ipos + 1
  111.         If (ipos Mod 10000) = 0 Then
  112.             Me.Caption = ipos & "/" & FLen
  113.             DoEvents
  114.         End If
  115.     Wend
  116.     Close infileNumber
  117.     Close outfileNumber
  118.     MsgBox "file processed in " & DateDiff("s", startTime, Now) & " seconds"
  119. End Sub
  120.