multiple opening of text files in vb6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronin
    New Member
    • Feb 2007
    • 25

    multiple opening of text files in vb6.0

    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.
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by Ronin
    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

    Comment

    • Ronin
      New Member
      • Feb 2007
      • 25

      #3
      Originally posted by vijaydiwakar
      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 FileSystemObjec t
      Dim txtstream As TextStream
      Dim outstream As TextStream
      Private Sub Command1_click( )

      Dim j As Integer
      Dim masterfile(1100 000) 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.ListC ount - 1
      If lstmarket.Selec ted(j) = True Then

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



      If Trim(txtweek) <= 9 And Len(Trim(txtwee k)) < 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\exercis e\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.OpenTextFi le("c:\Masterfi le.txt", ForWriting, True)
      Set txtstream = fsys.OpenTextFi le("C:\Rohit program\exercis e\SWD\" & filename, ForReading)
      Do Until txtstream.AtEnd OfStream
      masterline = txtstream.ReadL ine
      mastercount = mastercount + 1

      masterfile(mast ercount) = masterline

      For mastercount = 1 To mastercount - 1
      outstream.Write Line (masterline)
      Next mastercount
      Loop
      End Sub

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        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.

        Comment

        • Ronin
          New Member
          • Feb 2007
          • 25

          #5
          Originally posted by Killer42
          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*********** **********
          Code:
          For j = 0 To lstmarket.ListCount - 1
              If lstmarket.Selected(j) = True Then
                  Set outstream = fsys.OpenTextFile("c:\masterfile.txt", ForWriting, True)
                       For iday = 1 To 7
                          filename = lstmarket.List(j) & Trim(txtYear) & Trim(txtweek) & iday & ".swd"
                          If fsys.FileExists("C:\Rohit program\exercise\swd\" & filename) = False Then
                              MsgBox "file does not exist"
                              Exit Sub
                          End If
                          Set txtstream = fsys.OpenTextFile("C:\Rohit program\exercise\swd\" & filename, ForReading)
                              Do Until txtstream.AtEndOfStream
                                  masterline = txtstream.ReadLine
                                  outstream.WriteLine (masterline)
                              Loop
                          txtstream.Close
                      Next iday
                  outstream.Close
              End If
           Next j
           
           MsgBox "completed"
          Last edited by Killer42; Mar 3 '07, 11:31 PM. Reason: Please use CODE tags around your code.

          Comment

          Working...