Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change class in File

Posted on 2004-08-23
4
Medium Priority
?
290 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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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