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

x
?
Solved

Change Text File

Posted on 2004-08-19
7
Medium Priority
?
142 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
[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
  • 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:
Bob Lamberson earned 1000 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:Bob Lamberson
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

609 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