Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Export data to a *.csv file
Author:
Daniel M. Ionescu
E-mail:
Click to e-mail author
Submitted:
1/21/2004
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
44891
You can export from a user defined data structure. A new file is created each time the export procedure is called.
Declarations:
Dim nfile As Integer Dim conx as Integer
Code:
Private Sub cmdExport_Click() nfile = FreeFile ProgressBar1.Value = 1 Open "filea" For Output As #nfile For conx = 1 To nbr StatusBar1.Panels(1).Text = CInt(conx * 100 / nbr) & "% completed" 'Print to file each field of the structure "Customer" Print #nfile, conx & ", " & Customer(conx).Field1 & ", " & Customer(conx).Field2 & ", " & Customer(conx).Field3 & ", " & Customer(conx).Field4 & ", " & Customer(conx).Field5 & ", " & Customer(conx).Field6 & ", " ProgressBar1.Value = conx * 100 / nbr Next conx Close #nfile FileCopy "filea", App.Path & "\ExportedFile.csv" Kill "filea" If err.Number = 0 Then MsgBox "File exported to working directory!" Else MsgBox "Error exporting file: " & err.Number End If End Sub 'The data structure has to be defined like this one: Type Customer Field1 as String Field2 as String 'You can add as many fields as you need ... End Type
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement