By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

multiple opening of text files in vb6.0

P: 25
Hi guys,

I have a problem regarding a txt file operations.I have a listbox which has
various 3 digits numbers.there are 2 txtboxes on my form .now suppose if
check 101 from check box and write 1 and 7 in txtboxes i should be able to open all the files having the numbe 10117.
to inform u guys the files are txtfiles having names

10117051

where101 is market no 17 is the year and 05 is week and 1to 7 may be day

so i mean there are 7 files 10117051
10117052
10117053

and so on till 10117057


i need to copy all the contents of this file into a new single file.

If naybody caN HELP ME ,IT WOULD BE A GREAT HELP.
Feb 27 '07 #1
Share this Question
Share on Google+
4 Replies

vijaydiwakar
100+
P: 579
Hi guys,

I have a problem regarding a txt file operations.I have a listbox which has
various 3 digits numbers.there are 2 txtboxes on my form .now suppose if
check 101 from check box and write 1 and 7 in txtboxes i should be able to open all the files having the numbe 10117.
to inform u guys the files are txtfiles having names

10117051

where101 is market no 17 is the year and 05 is week and 1to 7 may be day

so i mean there are 7 files 10117051
10117052
10117053

and so on till 10117057


i need to copy all the contents of this file into a new single file.

If naybody caN HELP ME ,IT WOULD BE A GREAT HELP.
yes u can for that use directory ctrl give the path to it then it will give u entire list of files apply mid$ function to filenames if it matches then open it
try it by ur self
Feb 27 '07 #2

P: 25
yes u can for that use directory ctrl give the path to it then it will give u entire list of files apply mid$ function to filenames if it matches then open it
try it by ur self


Here is a piece of code i have written for it
Option Explicit
Dim fsys As New FileSystemObject
Dim txtstream As TextStream
Dim outstream As TextStream
Private Sub Command1_click()

Dim j As Integer
Dim masterfile(1100000) As String
Dim masterline As String
Dim iday As Integer
Dim mastercount As Integer
For iday = 1 To 7
mastercount = 0


For j = 0 To lstmarket.ListCount - 1
If lstmarket.Selected(j) = True Then

If Len(Trim(txtYear)) > 2 Or IsNumeric(Trim(txtYear)) = False Then
MsgBox "There should be a 2 digit number"
txtYear.Text = ""
txtYear.SetFocus
Exit Sub
End If



If Trim(txtweek) <= 9 And Len(Trim(txtweek)) < 2 Then
txtweek = "0" & Trim(txtweek)
End If
filename = lstmarket.List(j) & Trim(txtYear) & Trim(txtweek) & iday & ".txt"
MsgBox ("You have selected the following file" & filename)

End If
Next j
Next iday

If fsys.FileExists("C:\Rohit program\exercise\SWD\" & filename) = True Then
MsgBox ("The files are opened for manipulation")
Else
MsgBox ("File not found")
End If



*********** the main coding starts from here*************

Set outstream = fsys.OpenTextFile("c:\Masterfile.txt", ForWriting, True)
Set txtstream = fsys.OpenTextFile("C:\Rohit program\exercise\SWD\" & filename, ForReading)
Do Until txtstream.AtEndOfStream
masterline = txtstream.ReadLine
mastercount = mastercount + 1

masterfile(mastercount) = masterline

For mastercount = 1 To mastercount - 1
outstream.WriteLine (masterline)
Next mastercount
Loop
End Sub
Feb 28 '07 #3

Expert 5K+
P: 8,434
I kind of like vijaydiwakar's suggestion. The FileListBox control will be useful for this. Just plug in the Path, and the Pattern (that's the filename with wildcards) and it will list all the matching files - then you just run through the list and read each file.
Mar 1 '07 #4

P: 25
I kind of like vijaydiwakar's suggestion. The FileListBox control will be useful for this. Just plug in the Path, and the Pattern (that's the filename with wildcards) and it will list all the matching files - then you just run through the list and read each file.

no probs a little bit of thinking and i got the code done.here is a sample piece of my code

*** it is just a part of my code that selects all the 7 files and write that into the master file*********************
Expand|Select|Wrap|Line Numbers
  1. For j = 0 To lstmarket.ListCount - 1
  2.     If lstmarket.Selected(j) = True Then
  3.         Set outstream = fsys.OpenTextFile("c:\masterfile.txt", ForWriting, True)
  4.              For iday = 1 To 7
  5.                 filename = lstmarket.List(j) & Trim(txtYear) & Trim(txtweek) & iday & ".swd"
  6.                 If fsys.FileExists("C:\Rohit program\exercise\swd\" & filename) = False Then
  7.                     MsgBox "file does not exist"
  8.                     Exit Sub
  9.                 End If
  10.                 Set txtstream = fsys.OpenTextFile("C:\Rohit program\exercise\swd\" & filename, ForReading)
  11.                     Do Until txtstream.AtEndOfStream
  12.                         masterline = txtstream.ReadLine
  13.                         outstream.WriteLine (masterline)
  14.                     Loop
  15.                 txtstream.Close
  16.             Next iday
  17.         outstream.Close
  18.     End If
  19.  Next j
  20.  
  21.  MsgBox "completed"
Mar 2 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.