Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 File Size Limit

Author  Topic 

tecknowledge1164
Starting Member

25 Posts

Posted - 2006-08-11 : 13:39:02
Hello All,

I am working with an application written in Visual Basic 6 that connects to a SQL database. There is a form that has code in it where I query the database and create a .csv text file to be output. No problem so far, but one of the requirements is that the size of the file can't be more than 256K. How do I test for this so that I can trap it in my code? Thanks.

Bob Thompson

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-08-11 : 14:49:55
Bob,

If you're creating the .csv file directly from your VB6 app, you can just keep track of the amount of data you're writing to the file as you create each row. If there's room for the next row, write it to the file; if there's not, close that file and create/open a new one to hold more data.

The easiest way is to use a variable to hold each row. You read the first field and store it in the variable (adding quotes if it contains spaces, of course), and add a trailing comma. Read the next field and concatenate it to the variable (again adding quotes if needed), and add another comma, and so forth. Once you've added everything and have a complete row, use Len(yourVar) and save it to an integer variable (Size, for example). Write the row to the .csv file. Repeat reading another row, and then check to see if Len(yourVar) + Size > 256K; if not, write the row to the file and add Len(yourVar) to Size; if so, close the file and open a new one, reset Size to Len(yourVar), and write yourVar to the new file.

Ken
Go to Top of Page
   

- Advertisement -