?
Solved

Change Text File

Posted on 2004-08-19
7
Medium Priority
?
140 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 1 hour left to enroll

752 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