Avatar of jazjef
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...
Visual Basic ClassicVisual Basic.NET.NET Programming

Avatar of undefined
Last Comment
VBClassicGuy

8/22/2022 - Mon
kbirecki

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?
BrianVSoft

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..
jazjef

ASKER
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.....
Your help has saved me hundreds of hours of internet surfing.
fblack61
kbirecki

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.
BrianVSoft

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.
ASKER CERTIFIED SOLUTION
VBClassicGuy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kbirecki

VBClassicGuy, now that's a silver platter!  That looks like a lot of work.  Good job!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jazjef

ASKER
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
Printer.EndDoc

 
jazjef

ASKER
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
CommonDialog3.ShowPrinter

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

Printer.EndDoc
VBClassicGuy

Well, thank you , Sir. Glad to help out. Happy coding...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes