[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Limit Number of Characters per Row in .txt File

Hello,
There is a group at my company that needs to submit their documents to another company in ASCII format but for some reason this company won't let them use the program that will format all of this for them.
I was wondering if there was any way to write a script (ideally vbscript) to limit the number of characters per line in a notepad document to 98? I've been looking everywhere and I can't seem to find anything.

Thank you
0
Brent387
Asked:
Brent387
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what should happen when there are > 98 characters in the line?
wrap?  or cut?
0
 
Brent387Author Commented:
wrap
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
here we go
strFile = "C:\source_file.txt"
strDest = "C:\dest_file.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFile)

If objFile.Size > 0 Then
    Set objReadFile = objFSO.OpenTextFile(strFile, 1)
    Set objWriteFile = objFSO.OpenTextFile(strDest, ForOutPut, True)

    while not objReadFile.AtEndOfStream
      strLine = objReadFile.ReadLine
      while strLine <> ""
         objWriteFile.WriteLine(left(strLine, 98))
         strLine = mid(strLine, 99)
      Wend

    Wend
    objReadFile.Close
    objWriteFile.Close
Else
    Wscript.Echo "The source file does not exist."
End If

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rlandquistCommented:
I think line 9 should be:
Set objWriteFile = objFSO.CreateTextFile(strDest,  True)
unless you are pre creating the destination file before running the script.
0
 
Brent387Author Commented:
Line 9 was off but it was corrected.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry for that, copy/pasted the line and forgot to change the method name ...
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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now