📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1275
ClientLeft = 1620
ClientTop = 1545
ClientWidth = 1995
LinkTopic = "Form1"
ScaleHeight = 1275
ScaleWidth = 1995
Begin VB.CommandButton Command1
Caption = "Print Data"
Height = 495
Left = 360
TabIndex = 0
Top = 360
Width = 1215
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 MakeData()
Const NUM_POINTS = 40
Dim db As Database
Dim dbname As String
Dim i As Integer
Dim the_year As Date
Dim the_value As Single
Dim sql As String
' Open the database.
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)
' Delete any old data.
sql = "DELETE FROM YearlyValues"
db.Execute sql
' Create a bunch of data.
the_year = #1/1/30#
the_value = 1000
Do While the_year <= #1/1/2020#
sql = "INSERT INTO YearlyValues VALUES (#" & _
Format$(the_year) & "#, " & _
Format$(the_value) & ")"
db.Execute sql
the_year = DateAdd("yyyy", 1, the_year)
the_value = the_value * (1 + Rnd * 0.2)
Loop
db.Close
End Sub
Private Sub Command1_Click()
' Use 1 inch margins.
Const TOP_MARGIN = 1440
Const LEFT_MARGIN = 1440
Dim bottom_margin As Single
Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset
Dim dbname As String
Dim the_year As Integer
Dim the_value As Integer
MousePointer = vbHourglass
DoEvents
' Open the database.
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)
' Get the records.
Set qdef = db.CreateQueryDef("", _
"SELECT Year, Value FROM YearlyValues")
Set rs = qdef.OpenRecordset(dbOpenSnapshot)
' Read the data and print it.
bottom_margin = Printer.ScaleTop + _
Printer.ScaleHeight - 1440
rs.MoveFirst
Printer.CurrentY = TOP_MARGIN
Do While Not rs.EOF
' Use rs!FieldName to get the data for
' the field named FieldName.
Printer.CurrentX = LEFT_MARGIN
Printer.Print _
Format$(rs!Year, "yyyy") & _
vbTab & _
Format$(rs!Value, "0.0000")
' See if we have filled the page.
If Printer.CurrentY >= bottom_margin Then
' Start a new page.
Printer.NewPage
Printer.CurrentY = TOP_MARGIN
End If
rs.MoveNext
Loop
rs.Close
db.Close
' Finish printing.
Printer.EndDoc
MousePointer = vbDefault
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -