Solved

Change class in File

Posted on 2004-08-23
4
255 Views
Last Modified: 2010-05-02
I have a program that creates a tab delimited text file each day.   I have attempted to write a program to open each file individually (ie if there is one or 20 of the files), change the 5th field, and call the file the same name.    I need this to be without any imput from the user ie, when the program executes the class is changed and a log file is made(haven't done this part yet).    As yet my code does not seem to complete the task correctly.

Can anyone advise improvements to this

Dim AllFolders As New Collection
Private Sub changeClass(FILENAME As String)
    Const NEWFILENAME As String = "d:\test\newqbpos.txt"
   
    Dim TEMP As String
    Dim FIELDS() As String
    Dim I As Long
    Dim NEWLINE As String
   
        Open FILENAME For Input As #1
        Open NEWFILENAME For Output As #2
       
            While Not EOF(1)
                Line Input #1, TEMP
                FIELDS = Split(TEMP, vbTab)
                If FIELDS(0) = "TRNS" Or FIELDS(0) = "SPL" Then FIELDS(5) = "Myer Center"
                NEWLINE = ""
                For I = 0 To UBound(FIELDS)
                    NEWLINE = NEWLINE & FIELDS(I)
                    If UBound(FIELDS) <> I Then NEWLINE = NEWLINE & vbTab
                Next
                Print #2, NEWLINE
            Wend
        Close #1
        Close #2

End Sub
Private Sub GetSubFolders(ByVal Directory As String)
Dim FSO, tmpGet, tmpSub, tmpFolder
Dim CurrentFolders As New Collection

Set FSO = CreateObject("Scripting.FileSystemObject")
Set tmpGet = FSO.GetFolder(Directory)
Set tmpSub = tmpGet.SubFolders

For Each tmpFolder In tmpSub
If Right$(Directory, 1) = "\" Then
AllFolders.Add Directory & tmpFolder.Name
CurrentFolders.Add Directory & tmpFolder.Name
Else
AllFolders.Add Directory & "\" & tmpFolder.Name
CurrentFolders.Add Directory & "\" & tmpFolder.Name
End If
Next

For Each tmpFolder In CurrentFolders
GetSubFolders (tmpFolder)
Next
End Sub

Private Sub GetFiles(ByVal Directory As String)
Dim FSO, tmpGet, tmpSub, tmpFile
Dim CurrentFiles As New Collection

Set FSO = CreateObject("Scripting.FileSystemObject")
Set tmpGet = FSO.GetFolder(Directory)
Set tmpSub = tmpGet.Files

For Each tmpFile In tmpSub
changeClass (tmpFile) 'sub program to change class
Next
End Sub

Private Sub Form_Load()
Dim tmpFolder

GetSubFolders ("D:\test") 'Directory to be set will include PDB file

For Each tmpFolder In AllFolders
GetFiles tmpFolder
Next
End Sub


Also there will be other files in the directory so the changes can only occur if the file extension is TXT

Many Kind Regards


Brendon Gardiner
0
Comment
Question by:BrendonG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:BrendonG
ID: 11889373
This is now urgent so I will give it the full 500 points
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 500 total points
ID: 11891343
BrendonG,

What problem are you having?

I do see one problem in your code, since VB uses 0-based arrays, the line

If FIELDS(0) = "TRNS" Or FIELDS(0) = "SPL" Then FIELDS(5) = "Myer Center"

should be

If FIELDS(0) = "TRNS" Or FIELDS(0) = "SPL" Then FIELDS(4) = "Myer Center"

to update the 5th column


Dang123
0
 

Author Comment

by:BrendonG
ID: 11891364
Don't worry, Ive fixed it my self...how do I cancel this q
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question