?? form1.frm
字號:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "將數據庫文件轉換為文本文件"
ClientHeight = 5370
ClientLeft = 1125
ClientTop = 1500
ClientWidth = 7365
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
PaletteMode = 1 'UseZOrder
ScaleHeight = 5370
ScaleWidth = 7365
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.TextBox text1
Height = 285
Left = 1725
TabIndex = 5
Top = 255
Width = 4980
End
Begin VB.TextBox text2
Height = 285
Left = 1725
TabIndex = 4
Top = 3315
Width = 4980
End
Begin VB.CommandButton Command2
Caption = "退出"
Height = 465
Left = 6270
TabIndex = 3
Top = 1980
Width = 810
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "E:\編程技巧\xcx\數據庫\1數據庫轉為文本\db1.mdb"
DefaultCursorType= 0 '缺省游標
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 345
Left = 5430
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "sy"
Top = 5250
Visible = 0 'False
Width = 1605
End
Begin MSDBGrid.DBGrid DBGrid1
Bindings = "Form1.frx":0000
Height = 2355
Left = 270
OleObjectBlob = "Form1.frx":0014
TabIndex = 2
Top = 780
Width = 5805
End
Begin RichTextLib.RichTextBox RichText1
Height = 1530
Left = 270
TabIndex = 1
Top = 3705
Width = 6795
_ExtentX = 11986
_ExtentY = 2699
_Version = 393217
ScrollBars = 3
TextRTF = $"Form1.frx":09B6
End
Begin VB.CommandButton command1
Caption = "轉換"
Height = 465
Left = 6270
TabIndex = 0
Top = 1380
Width = 810
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "數據庫路徑"
Height = 180
Index = 0
Left = 240
TabIndex = 7
Top = 285
Width = 960
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "輸出文本文件路徑"
Height = 180
Index = 1
Left = 240
TabIndex = 6
Top = 3345
Width = 1440
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
Data1.DatabaseName = App.Path & "\db1.mdb" '綁定數據源
text1.Text = App.Path & "\db1.mdb"
text2.Text = App.Path & "\db1.txt"
End Sub
Private Sub Command1_Click() '轉換數據庫數據為文本文件
Dim fnum As Integer
Dim file_name As String
Dim database_name As String
Dim mydb As Database
Dim myrs As Recordset
Dim numcount As Integer
Dim i As Integer
Dim num As Integer
Dim swidth() As Integer
Dim svalue As String
fnum = FreeFile
file_name = text2.Text
Open file_name For Output As fnum
Set mydb = OpenDatabase(text1.Text) '打開數據庫
Set myrs = mydb.OpenRecordset("SELECT * FROM sy") '打開記錄集
numcount = myrs.Fields.Count
ReDim swidth(0 To numcount - 1)
For i = 0 To numcount - 1
swidth(i) = myrs.Fields(i).Size
If swidth(i) < Len(myrs.Fields(i).Name) Then
swidth(i) = Len(myrs.Fields(i).Name)
End If
swidth(i) = swidth(i) + 1
Print #fnum, myrs.Fields(i).Name; '數據寫入文本
Print #fnum, Space$(swidth(i) - Len(myrs.Fields(i).Name)) '寫入空格
Next i
Print #fnum, "" '寫入空行
Do While Not myrs.EOF
num = num + 1
For i = 0 To numcount - 1
svalue = myrs.Fields(i).Value
Print #fnum, svalue & Space$(swidth(i) - Len(svalue));
Next i
Print #fnum, ""
myrs.MoveNext '下一條記錄
Loop
myrs.Close '關閉記錄集
mydb.Close '關閉數據庫
Close fnum
RichText1.FileName = text2.Text
End Sub
Private Sub Command2_Click()
End
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -