home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form FILEIOForm
- Caption = "File I/O Demo"
- ClientHeight = 2355
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 4410
- LinkTopic = "Form1"
- ScaleHeight = 2355
- ScaleWidth = 4410
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command2
- Caption = "Process Binary File"
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 840
- Width = 1815
- End
- Begin MSComDlg.CommonDialog CommonDialog1
- Left = 1440
- Top = 1560
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- End
- Begin VB.CommandButton Command1
- Caption = "Process Text File"
- Height = 495
- Left = 120
- TabIndex = 0
- Top = 240
- Width = 1815
- End
- Attribute VB_Name = "FILEIOForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub Command1_Click()
- Dim infile As String, outfile As String
- Dim infileNumber As Integer, outfileNumber As Integer
- Dim tline As String
- Dim outline As String
- CommonDialog1.FileName = ""
- CommonDialog1.Filter = "Text Files|*.TXT"
- CommonDialog1.ShowOpen
- infile = CommonDialog1.FileName
- If infile = "" Then Exit Sub
- GetOutFileName:
- CommonDialog1.FileName = ""
- CommonDialog1.ShowSave
- outfile = CommonDialog1.FileName
- If outfile = "" Then Exit Sub
- If infile = outfile Then
- MsgBox "This application will not overwrite the source file." & vbCrLf & _
- "Please select another output file name"
- GoTo GetOutFileName
- End If
- infileNumber = FreeFile
- Open infile For Input Access Read As #infileNumber
- outfileNumber = FreeFile
- Open outfile For Output Access Write As #outfileNumber
- While Not EOF(infileNumber)
- Line Input #infileNumber, tline
- outline = Process(tline)
- Print #outfileNumber, outline
- Wend
- Close infileNumber
- Close outfileNumber
- End Sub
- Function Process(txt) As String
- Process = UCase(txt)
- End Function
- Private Sub Command2_Click()
- Dim infile As String, outfile As String
- Dim infileNumber As Integer, outfileNumber As Integer
- Dim tline As String
- Dim outline As String
- CommonDialog1.FileName = ""
- CommonDialog1.Filter = "All Files|*.*"
- CommonDialog1.ShowOpen
- infile = CommonDialog1.FileName
- If infile = "" Then Exit Sub
- GetOutFileName:
- CommonDialog1.FileName = ""
- CommonDialog1.ShowSave
- outfile = CommonDialog1.FileName
- If outfile = "" Then Exit Sub
- If infile = outfile Then
- MsgBox "This application will not overwrite the source file." & vbCrLf & _
- "Please select another output file name"
- GoTo GetOutFileName
- End If
- infileNumber = FreeFile
- Open infile For Binary Access Read As #infileNumber
- outfileNumber = FreeFile
- Open outfile For Binary Access Write As #outfileNumber
- Dim inChar As Byte, outChar As Byte
- Dim startTime As Date
- Dim ipos As Long
- startTime = Now
- i = 0
- FLen = LOF(infileNumber)
- While Not EOF(infileNumber)
- Get #infileNumber, , inChar
- outChar = inChar
- Put #outfileNumber, , outChar
- ipos = ipos + 1
- If (ipos Mod 10000) = 0 Then
- Me.Caption = ipos & "/" & FLen
- DoEvents
- End If
- Wend
- Close infileNumber
- Close outfileNumber
- MsgBox "file processed in " & DateDiff("s", startTime, Now) & " seconds"
- End Sub
-