VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Export a Grid to a text file

by Waty Thierry (60 Submissions)
Category: Graphics
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Tue 30th March 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Export a Grid to a text file

Rate Export a Grid to a text file



   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : [email protected]
   ' * Date             : 13/10/98
   ' * Time             : 09:18
   ' * Module Name      : Grid_Module
   ' * Module Filename  : Grid.bas
   ' **********************************************************************
   ' * Comments         : Export a grid to a text file
   ' **********************************************************************

Public Sub GridExport(GridToExport _
            As Object, FileName As String, Optional _
            Delimiter As Variant, Optional _
            EncloseStrings As Variant)
    Dim iNumRows As Integer
    Dim iNumCols As Integer
    Dim iFileNumber As Integer
 
    If IsMissing(Delimiter) Then
        Delimiter = vbTab
    End If
    If IsMissing(EncloseStrings) Then
        EncloseStirngs = ""
    End If
    iFileNumber = FreeFile
    Open FileName For Output As #iFileNumber
    For iNumRows = 0 To _
                GridToExport.rows - 1
        GridToExport.Row = iNumRows
        For iNumCols = 0 To _
                    GridToExport.Cols - 1
            GridToExport.col = iNumCols
            'if it isn't the first column,
            'put a delimiter before the value
            If iNumCols > 0 Then
                Print #iFileNumber, Delimiter;
            End If
            Print #iFileNumber, EncloseStrings & _
                    GridToExport.Text & EncloseStrings;
        Next iNumCols
        Print #iFileNumber, ""
    Next iNumRows
    Close #iFileNmuber
End Sub
 
Private Sub cmdExport_Click()
    Call GridExport(MSFlexGrid1, "c:/test.csv", ",", Chr$(34))
End Sub
 
Private Sub Form_Load()
    MSFlexGrid1.AddItem "Sam Huggill"
    MSFlexGrid1.AddItem "VB Square"
End Sub


Download this snippet    Add to My Saved Code

Export a Grid to a text file Comments

No comments have been posted about Export a Grid to a text file. Why not be the first to post a comment about Export a Grid to a text file.

Post your comment

Subject:
Message:
0/1000 characters