Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

Import and split long text into bits of 80 charters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Leika - 18 Mar 2005 01:53 GMT
I’m quit new at this, so I could really need some help, to make some VBA code
for my problem.
I have a text file with all of the text in one single line, but I need it to
be in lines of 80 charters, and maybe save it to a new text file.
From there it isn’t such a hard task to get the information out of it, I
just have to import it as a fixed with file.

I really hope somebody can help me, then until now I have made the first
part by hand.
Thanks in advanced.
Dirk Goldgar - 18 Mar 2005 03:52 GMT
> I'm quit new at this, so I could really need some help, to make some
> VBA code for my problem.
[quoted text clipped - 7 lines]
> first part by hand.
> Thanks in advanced.

Here's some sample code:

'----- start of code -----
Sub MakeFile80()

   Dim lngBytesLeft As Long
   Dim iFileIn As Integer
   Dim iFileOut As Integer
   Dim strLine As String

   iFileIn = FreeFile
   Open "C:\Temp\OneLongLine.txt" For Input As iFileIn

   iFileOut = FreeFile
   Open "C:\Temp\Fixed80Lines.txt" For Output As iFileOut

   lngBytesLeft = LOF(iFileIn)

   Do While lngBytesLeft > 0

       If lngBytesLeft < 80 Then
           strLine = Input(lngBytesLeft, iFileIn)
           ' Drop trailing CR/LF if present.
           If Right(strLine, 2) = vbCrLf Then
               strLine = Left(strLine, Len(strLine) - 2)
           End If
           ' Pad short line to 80 bytes.
           strLine = Left(strLine & Space(80), 80)
           lngBytesLeft = 0
       Else
           strLine = Input(80, iFileIn)
           lngBytesLeft = lngBytesLeft - 80
       End If

       Print #iFileOut, strLine

   Loop

   Close iFileIn, iFileOut

End Sub
'----- end of code -----

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Leika - 18 Mar 2005 11:43 GMT
Thanks.
It was a super answer, and it worked perfect.
Now I can get on with my project.

"Dirk Goldgar" skrev:

> > I'm quit new at this, so I could really need some help, to make some
> > VBA code for my problem.
[quoted text clipped - 50 lines]
> End Sub
> '----- end of code -----
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.