Link to home
Start Free TrialLog in
Avatar of jazjef

asked on

How do I send MSFlexGrid data to a tab-delimited text file in VB6 so that all the columns remain aligned?

I want to send the data from VB6 MSFlexGrid1 to a tab-delimited text file and preserve the column alignments. Anyone know how to do this? Thanks for any help...
Avatar of kbirecki
Flag of United States of America image

Ok, first, tab delimited text files won't look like the columns are aligned unless you open in an app like Excel that can show columns properly.  Is that what you expect?

Regarding the flexgrid, is your data based on a record set or data you manually pushed into the control?
Kbirecki is correct.. Tabs in a plain text file don't automatically present the text in columns. Only the application used to view the text file can use the tabs to attempt to display it in columns.
Excel won't do it directly, you have to import the file into excel and confirm that it is a TAB file.
Other Apps like Wordpad still require you to set TAB widths manually..
What do you plan to use this file for? A Printed Report? or to email this file as an Invoice or Report?
This might help the ExEx folk give you some specific advice..
Avatar of jazjef


I would like it to be printable---but viewable as a text file type report so you don't need Excel in order to view it. The data would be manually pushed/entered into the control----there would be no recordset or datasource feeding it. What about the DataReports feature? Could you feed it from an MSFlexGrid? Are there any add-ons that will take the data of a grid and generate a simple report that you know of. Thanks for the responses.....
The MSFlexGrid is a display element.  I think whatever your source is should be the source for any other output.  Otherwise you;d have to write something that parses the contents of the flexgrid to spit them back out somewhere.  If you have the data to put into the flexgrid, just use that to push to your output format.

As for a text file output in columns, you also have to think about whether the viewer is using a monospace font or not.  Monospace fonts allow you to display text in columns, but only if you can be sure the recipient is using a viewer that is showing in monospace.
By using Printer.CurrentX and Printer.CurrentY you can print each cell text to exact column widths. You can even print vertical lines between the columns and a box around the whole format..
Then, by using one of the free PDF printer apps, you can direct that same printout to a PDF file which can be viewed by most PC users. The viewer is freely available.
Avatar of VBClassicGuy
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
VBClassicGuy, now that's a silver platter!  That looks like a lot of work.  Good job!
Avatar of jazjef


That's pretty elaborate vbclassicguy.... over my head; I don't know if I can implement that. I was thinking about something like this.... it will print an msflexgrid but without a vbcrlf somewhere if you print more than 1 then they print on top of each other. This will send an msflexgrid to Primo PDF or my HP Laserjet printer....

'0 = Primo PDF printer
'1 = print-to-file dialog
'2 = *.xps
'3 = ERROR
'4 = Laserjet 110
'5 = sendfax

Set Printer = Printers(0)
Printer.PaintPicture grd_VisStats.Picture, 0, 0

Avatar of jazjef


Nice solution VBClassicGuy... major-league coding. I have included another method I got to work in case anyone following this post is interested. Thanks to all....

'_____PRINT the gridview controls

CommonDialog3.PrinterDefault = True
CommonDialog3.CancelError = True

'_____Set flags - no page numbers, return the selected printer
CommonDialog3.flags = cdlPDReturnDC + cdlPDNoPageNums

'_____Enables error handling to catch cancel error
On Error Resume Next
'_____display the print dialog box

If Err Then
    '_____This code runs if the dialog was cancelled
    MsgBox "Printing Cancelled"
    Exit Sub
End If

'____Prints the msflexgrids
Printer.PaintPicture MSFlexGrid1.Picture, 500, 500
Printer.PaintPicture MSFlexGrid2.Picture, 500, 5000
Printer.PaintPicture MSFlexGrid3.Picture, 500, 9500

Well, thank you , Sir. Glad to help out. Happy coding...