home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmMerge
- Caption = "Merge Two Files"
- ClientHeight = 2040
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 3495
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 2040
- ScaleWidth = 3495
- Begin VB.PictureBox picProgress
- Height = 255
- Left = 360
- ScaleHeight = 195
- ScaleWidth = 2715
- TabIndex = 7
- Top = 1680
- Width = 2775
- End
- Begin VB.CommandButton cmdProceed
- Caption = "Proceed to Merge"
- Height = 375
- Left = 720
- TabIndex = 6
- Top = 1200
- Width = 2055
- End
- Begin VB.TextBox txtNameMerged
- Height = 285
- Left = 2160
- TabIndex = 5
- Top = 840
- Width = 1215
- End
- Begin VB.TextBox txtNameSecond
- Height = 285
- Left = 2160
- TabIndex = 3
- Top = 480
- Width = 1215
- End
- Begin VB.TextBox txtNameFirst
- Height = 285
- Left = 2160
- TabIndex = 1
- Top = 120
- Width = 1215
- End
- Begin VB.Label lblNameMerged
- Alignment = 1 'Right Justify
- Caption = "Name for merged file:"
- Height = 255
- Left = 120
- TabIndex = 4
- Top = 840
- Width = 1935
- End
- Begin VB.Label lblNameSecong
- Alignment = 1 'Right Justify
- Caption = "Name of second file:"
- Height = 255
- Left = 240
- TabIndex = 2
- Top = 480
- Width = 1815
- End
- Begin VB.Label lblNameFirst
- Alignment = 1 'Right Justify
- Caption = "Name of first file:"
- Height = 255
- Left = 360
- TabIndex = 0
- Top = 120
- Width = 1695
- End
- Attribute VB_Name = "frmMerge"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub cmdProceed_Click()
- Dim file1 As String, file2 As String, file3 As String
- Dim have1data As Boolean, have2data As Boolean
- Dim num1 As Single, num2 As Single
- Dim recCount As Integer
- 'Merge two ordered files
- picProgress.Cls
- file1 = txtNameFirst.Text
- file2 = txtNameSecond.Text
- file3 = txtNameMerged.Text
- Open App.Path & "\" & file1 For Input As #1
- Open App.Path & "\" & file2 For Input As #2
- Open App.Path & "\" & file3 For Output As #3
- have1data = Get1data(num1)
- have2data = Get2data(num2)
- recCount = 0
- Do While have1data And have2data
- Select Case num1
- Case Is < num2
- Write #3, num1
- have1data = Get1data(num1)
- Case Is > num2
- Write #3, num2
- have2data = Get2data(num2)
- Case num2
- Write #3, num1
- have1data = Get1data(num1)
- have2data = Get2data(num2)
- End Select
- recCount = recCount + 1
- Loop
- Do While have1data
- Write #3, num1
- recCount = recCount + 1
- have1data = Get1data(num1)
- Loop
- Do While have2data
- Write #3, num2
- recCount = recCount + 1
- have2data = Get2data(num2)
- Loop
- Close #1, #2, #3
- picProgress.Print recCount; "records written to "; file3
- End Sub
- Private Function Get1data(num1 As Single) As Boolean
- 'If possible, read next value from file 1
- 'Return value True when new data is read; False if data not available
- If Not EOF(1) Then
- Input #1, num1
- Get1data = True
- Else
- Get1data = False
- End If
- End Function
- Private Function Get2data(num2 As Single) As Boolean
- 'If possible, read next value from file 2
- 'Return value True when new data is read; False if data not available
- If Not EOF(2) Then
- Input #2, num2
- Get2data = True
- Else
- Get2data = False
- End If
- End Function
-