Solved

Change class in File

Posted on 2004-08-23
4
234 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

776 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