Solved

Change class in File

Posted on 2004-08-23
4
208 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
Comment Utility
This is now urgent so I will give it the full 500 points
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 500 total points
Comment Utility
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
Comment Utility
Don't worry, Ive fixed it my self...how do I cancel this q
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now