?
Solved

Writing to a text file

Posted on 2006-04-09
2
Medium Priority
?
191 Views
Last Modified: 2011-09-20
I'm using the following code below, which works fine, but is there someway I can automatically write to another file when the size of the initial one reaches 400KB and so on, so I could finish up with 10 400KB files rather than one 4MB file?

    CommonDialog1.ShowSave
    DoEvents
   
    If CommonDialog1.FileName <> "" Then
   
            Open Left(CommonDialog1.FileName, Len(CommonDialog1.FileName) - (Len(CommonDialog1.DefaultExt) + 1)) & Mid(CommonDialog1.DefaultExt, 2) For Append      As #1
          For ID = 1 To ProgressBar1.Max

            Print #1, Query
         Next
         Close #1
0
Comment
Question by:PeterErhard
2 Comments
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16410839
You could count the number of bytes in Query, and when it exceeds your limit, close the file, and write the rest
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 16411052
dim lngOffset as long
dim lngLen as long
dim lngPart as long
dim TrunkSize as long
dim intFile as integer

Trunksize = 400 * 1024
lngOffset = 1
lngPart = 1
lngLen = len(Query)

while lngOffset < lngLen
  intFile = freefile
  Open Left(CommonDialog1.FileName, Len(CommonDialog1.FileName) - (Len(CommonDialog1.DefaultExt) + 1)) & "." & lngPart & "." & Mid(CommonDialog1.DefaultExt, 2) For Append      As #intFile
  print #intFile, mid(Query, lngOffset, TrunkSize)
  close #intFile

  lngPart = lngPart + 1
  lngOffset = lngOffset + Trunksize  

wend
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 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