×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Change a txt file layout using a Visual Basic

Change a txt file layout using a Visual Basic

Change a txt file layout using a Visual Basic

(OP)
Hi,

I have this text to work on it:
16:04 -----------------------------
29-11-2007 16:04 CLIENT: devti-bck
29-11-2007 16:04 POLICY: devti-db2
29-11-2007 16:04 SCHEDULE: full
29-11-2007 16:04 SCHEDULE TYPE: FULL
29-11-2007 16:04 STATUS: 0
29-11-2007 16:04 STREAM: 0
29-11-2007 16:04 -----------------------------

It's about a exit status of a backup. Every backups ends, a new data it's enter in the file. I want to send all text to another file, not copy, because I need all text only in a line, using VB. Like this:
29-11-2007 16:04 CLIENT: devti-bck 29-11-2007 16:04 POLICY: devti-db2

RE: Change a txt file layout using a Visual Basic

Do you need to do this in VB or VBScript?  In VBScript it will be something like

CODE

<job>
<object id="objFSO" progid="Scripting.FileSystemObject" />
<script language="vbscript">
const ForReading = 1, ForWriting = 2
dim statusfile, oneliner, buff
set statusfile = objFSO.OpenTextFile (whatever, ForReading)
buff = statusfile.ReadAll
statusfile.close
replace (buff, vbCRLF, " ")
set oneliner = objFSO.CreateFile (anotherfile, true)
oneliner.WriteLine buff
oneliner.close
</script>
</job>

RE: Change a txt file layout using a Visual Basic

(OP)
I need a VB to run in a Windows 2003 server machine.

RE: Change a txt file layout using a Visual Basic

VBScript will run on W2003 but if you want VB

CODE

Const MULTILINE = 10, SINGLELINE = 20
Dim shortline As String, longline As String
Open "multi.txt" For Input As #MULTILINE

longline = ""
Do While Not EOF(MULTILINE)
   Line Input #MULTILINE, shortline
   longline = longline & " " & shortline
Loop
Close #MULTILINE

Open "single.txt" For Output As #SINGLELINE
Print #SINGLELINE, longline
Close #SINGLELINE

RE: Change a txt file layout using a Visual Basic

I would strongly recommend that you not use constants for file handles as that could lead to conflicts.  VB provides the build in function "FreeFile" which returns a valid and free file handle.

CODE

Dim MULTILINE As Integer, SINGLELINE As Integer
Dim shortline As String, longline As String

MULTILINE = FreeFile
Open "multi.txt" For Input As #MULTILINE

longline = ""
Do While Not EOF(MULTILINE)
   Line Input #MULTILINE, shortline
   longline = longline & " " & shortline
Loop
Close #MULTILINE

SINGLELINE = FreeFile
Open "single.txt" For Output As #SINGLELINE
Print #SINGLELINE, longline
Close #SINGLELINE

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

RE: Change a txt file layout using a Visual Basic

I'd forgotten about that: I've been using VBScript and VBA so much that I can hardly remember the finer points of VB.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close