Solved

Change Text File

Posted on 2004-08-19
7
127 Views
Last Modified: 2010-05-02
I have a Text file that is space delimited and want to add a digit (1) to a list (column) of fields. the field is changing from a five digit field to a six digit field.  the database only allows 5 digits on the original field. I need to save it to a different file as a text delimited file.

0
Comment
Question by:lopezt1
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:Enlade
ID: 11849141

I'm not sure I can help you with this problem, but I just have to ask.  What is a "text delimited file"?  Hee hee.

I think you need to restate your question differently.  Maybe give people an example of the input file (a line or two) and then give them an example of the output file (using the line or two from your input file).  I think if you do that you will get an answer quickly as your solution is probably just a loop, a line input, a split statement, and a print statement.
0
 
LVL 12

Accepted Solution

by:
BobLamberson earned 250 total points
ID: 11849193
Hi lopezt1,

Add the following code to a form code, and add a command button to the form.
Insert your path and file names where I have indicated (2 places) then run the form, click the button and open your output file to see the results.

Option Explicit
Dim fileName As String
Dim fso, ts
Dim inText As String
Dim newText As String
Dim txtArray() As String
Dim txtArrayLine() As String
Dim txtLine As String

Private Function getLine()
fileName = "C:\AAA testing\TextDocument\inputText.txt"      ' insert  your input path and filename here
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(fileName, ForReading, True)
If ts.AtEndOfStream <> True Then
   inText = ts.ReadAll
End If
ts.Close
addCharacter (inText)    'passing the file contents to addCharacter function.
Set fso = Nothing
Set ts = Nothing
End Function

Private Function addCharacter(newText As String)
Dim i As Integer
Dim outFileName As String
outFileName = "C:\AAA testing\TextDocument\outputText.txt"      ' insert  your output path and filename here
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(outFileName, ForWriting, True)
txtArray() = Split(newText, vbCrLf)       'put each Line in an Array element
For i = 0 To UBound(txtArray)
   txtArrayLine() = Split(txtArray(i), Chr(32))            'split out the columns
   txtArrayLine(3) = txtArrayLine(3) & "1"             'add the 1 here
   txtLine = Join(txtArrayLine, Chr(32))           'put the line back together
   ts.WriteLine (txtLine)               'write the line to the new file
Next i
ts.Close
Set fso = Nothing
Set ts = Nothing
End Function

Private Sub Command1_Click()
getLine
End Sub


Bob
0
 
LVL 7

Expert Comment

by:Enlade
ID: 11851107

I don't know how you wrote any code from that specification, but since you have a loop, a Split, and a WriteLine, it probably will work.  Hee hee.

0
 
LVL 12

Expert Comment

by:BobLamberson
ID: 12378127
lopezt1,

I think the code I posted answered your question. If not post the problem you are having with it and someone can probably help.
Bob
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…

948 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

19 Experts available now in Live!

Get 1:1 Help Now