Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No idea to export the msflexgrid in tabular output the complete calendar 1

Status
Not open for further replies.
This'll get you a string in tabular format with whatever separator you choose into a string. You can then write the string to a file. I leave that as an exercise for the reader

Code:
[COLOR=blue]Public Function FlexText(srcFlexgrid As MSFlexGrid, Optional Separator As String = " ") As String
    Dim row As Long
    Dim col As Long

    With srcFlexgrid
        For col = 0 To .Cols - 1
            For row = 0 To .Rows - 1
                FlexText = FlexText & .TextMatrix(row, col)
                If row < .Rows - 1 Then FlexText = FlexText & Separator
            Next
            If col < .Cols - 1 Then FlexText = FlexText & vbCrLf
        Next
    End With
End Function[/color]
 
strongm,
I may have a 'senior moment', but - shouldn't [tt]row[/tt] and [tt]col[/tt] logic be 'reversed'/flipped around... [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Touché! That'll teach me to use symmetrical data in my test set!

So, here's the correct version

Code:
[COLOR=blue]Public Function FlexText(srcFlexgrid As MSFlexGrid, Optional Separator As String = " ") As String
    Dim row As Long
    Dim col As Long

    With srcFlexgrid
        For row = 0 To .Rows - 1
            For col = 0 To .Cols - 1
                FlexText = FlexText & .TextMatrix(row, col)
                If col < .Cols - 1 Then FlexText = FlexText & Separator
            Next
            If row < .Rows - 1 Then FlexText = FlexText & vbCrLf
        Next
    End With
End Function[/color]
 
OK, tks.
but how to export into a txt file?
 
sal21 said:
how to export into a txt file?

Have you tried this approach [ponder]

strongm, I was hoping you are gonna leave it 'as an exercise for the reader' to reverse it...

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
>but how to export into a txt file?

strongm said:
You can then write the string to a file. I leave that as an exercise for the reader

I despair of you calling yourself a programmer if you don't know how to write a string to a file, particularly since you were about 1 or 2 lines of code away from the answer to that in your first post.

Here, I had a few moments:

Code:
[COLOR=blue]    hfile = FreeFile [COLOR=green]' best practice, rather than hardcoding a file handle[/color]
    Open MYFILE For Output As hfile [COLOR=green]' this is MYFILE from your original post[/color]
    Print #hfile, FlexText(MSFlexGrid1, vbTab);
    Close hfile[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top