⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 100个vb编程实例,什么都有
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1980
   ClientLeft      =   1620
   ClientTop       =   1545
   ClientWidth     =   4170
   LinkTopic       =   "Form1"
   ScaleHeight     =   1980
   ScaleWidth      =   4170
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   2280
      Top             =   1200
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "选择数据库文件"
      Height          =   495
      Left            =   480
      TabIndex        =   2
      Top             =   240
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      Height          =   495
      Left            =   1920
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   240
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "打印数据"
      Height          =   495
      Left            =   480
      TabIndex        =   0
      Top             =   1080
      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
Dim dbname As String
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/1930#
    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 the_year As Integer
Dim the_value As Integer

    MousePointer = vbHourglass
    DoEvents

    ' Open the database.
   
    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

Private Sub Command2_Click()
With CommonDialog1
    .CancelError = True
    .Filter = "数据库(*.mdb)|*.mdb"
    .Flags = cdlOFNHideReadOnly
    .ShowOpen
    If Err.Number = cdlCancel Then
        Err.Clear
        Exit Sub
    End If
   dbname = .FileName
   Text1.Text = .FileTitle
End With


End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -