📄 form1.frm
字号:
VERSION 4.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1815
ClientLeft = 1140
ClientTop = 1515
ClientWidth = 6255
Height = 2220
Left = 1080
LinkTopic = "Form1"
ScaleHeight = 1815
ScaleWidth = 6255
Top = 1170
Width = 6375
Begin VB.TextBox txtFileName
Height = 285
Left = 1080
TabIndex = 4
Top = 600
Width = 4935
End
Begin VB.TextBox txtDatabaseName
Height = 285
Left = 1080
TabIndex = 3
Top = 240
Width = 4935
End
Begin VB.CommandButton cmdExport
Caption = "Export"
Height = 495
Left = 2520
TabIndex = 2
Top = 1080
Width = 1215
End
Begin VB.Label Label1
Caption = "Output File"
Height = 255
Index = 1
Left = 240
TabIndex = 1
Top = 600
Width = 855
End
Begin VB.Label Label1
Caption = "Database"
Height = 255
Index = 0
Left = 240
TabIndex = 0
Top = 240
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
' Export the file.
Private Sub cmdExport_Click()
Dim fnum As Integer
Dim file_name As String
Dim database_name As String
Dim db As Database
Dim rs As Recordset
Dim num_fields As Integer
Dim field_width() As Integer
Dim field_value As String
Dim i As Integer
Dim num_processed As Integer
On Error GoTo MiscError
' Open the output file.
fnum = FreeFile
file_name = txtFileName.Text
Open file_name For Output As fnum
' Open the database.
Set db = OpenDatabase(txtDatabaseName.Text)
' Open the recordset.
Set rs = db.OpenRecordset( _
"SELECT * FROM Books ORDER BY Title")
' Start with the names of the fields.
num_fields = rs.Fields.Count
ReDim field_width(0 To num_fields - 1)
For i = 0 To num_fields - 1
' We're only working with Text here. Other
' types are different. For example, an
' integer may take 2 bytes to store but 6
' characters to display.
field_width(i) = rs.Fields(i).Size
If field_width(i) < Len(rs.Fields(i).Name) Then
field_width(i) = Len(rs.Fields(i).Name)
End If
field_width(i) = field_width(i) + 1
Print #fnum, rs.Fields(i).Name;
Print #fnum, Space$(field_width(i) - _
Len(rs.Fields(i).Name));
Next i
Print #fnum, ""
' Process the records.
Do While Not rs.EOF
num_processed = num_processed + 1
For i = 0 To num_fields - 1
field_value = rs.Fields(i).Value
Print #fnum, field_value & _
Space$(field_width(i) - _
Len(field_value));
Next i
Print #fnum, ""
rs.MoveNext
Loop
' Close the file and database.
rs.Close
db.Close
Close fnum
MsgBox "Processed " & _
Format$(num_processed) & " records."
Exit Sub
MiscError:
MsgBox "Error " & Err.Number & _
vbCrLf & Err.Description
End Sub
Private Sub Form_Load()
txtDatabaseName.Text = App.Path & "\books.mdb"
txtFileName.Text = App.Path & "\books.txt"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -