Solved

Change class in File

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

789 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