
I'm only able to do this far
Here's the code:
Dim lotno_data As String, dwg_data_array(3000) As String
Sub Search_lotno()
Dim Search_status As Integer, Total_rec As Integer
Close #1
Close #2
'UserForm1.TextBox1.Visible = True
On Error GoTo errhandle
Title = "Select a Source file in Q:\*.dat"
qfilename = Application.GetOpenFilename("Data Files (*.dat),*.dat,All Files(*.*),*.*", , Title)
If qfilename = False Then
MsgBox "No file was selected."
Exit Sub
End If
Title = "Select a target file name(from drawing)"
dwgfilename = Application.GetOpenFilename(, , Title)
If dwgfilename = False Then
MsgBox "No file was selected."
Exit Sub
End If
Title = "Enter Output file name"
outfilename = Application.GetSaveAsFilename("output.txt", , , Title)
If outfilename = False Then
MsgBox "No file was selected."
Exit Sub
End If
UserForm1.Hide
Open outfilename For Output As #3
Open dwgfilename For Input As #2
Worksheets(1).Select
Worksheets(1).Range("E17").Value = "Searching in progress.........."
Total_rec = 0
i = 1
Do While Not EOF(2)
File1_counter = 0
Line Input #2, dwg_data_array(i)
i = i + 1
Loop
total2 = i - 1
Close #1
Open qfilename For Input As #1
Do While Not EOF(1)
lotno_data = ""
Line Input #1, lotno_data
a = Len(lotno_data)
For j = 1 To total2
Search_status = InStr(lotno_data, dwg_data_array(j))
If Search_status > 0 Then
a = 15 - Len(dwg_data_array(j))
sperator_str = Space$(a) + "***"
outstring = dwg_data_array(j) + sperator_str + lotno_data
Print #3, outstring
Total_rec = Total_rec + 1
For k = j To (total2 - 1)
dwg_data_array(k) = dwg_data_array(k + 1)
Next
total2 = total2 - 1
Exit For
End If
Next
If total2 = 0 Then Exit Do
Loop
Close #2
Close #3
Worksheets(1).Range("E17").Value = ""
Total_str = Str(Total_rec)
prompt = "Search completed,Total record found= " + Total_str
MsgBox (prompt)
UserForm1.Show
Application.ActiveWorkbook.Save
'Application.ActiveWorkbook.Close
Exit Sub
errhandle:
MsgBox Error(Err)
Worksheets(1).Range("E17").Value = ""
'Application.ActiveWorkbook.Save
'Application.ActiveWorkbook.Close
Exit Sub
End Sub
Sub Auto_Open()
UserForm1.Show
End Sub

New Topic/Question
Reply



MultiQuote



|