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

📄 form1.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Option Strict On
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Font = New System.Drawing.Font("Comic Sans MS", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Button1.Location = New System.Drawing.Point(8, 208)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(264, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Count Files"
        '
        'TextBox1
        '
        Me.TextBox1.Font = New System.Drawing.Font("Comic Sans MS", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.Location = New System.Drawing.Point(8, 8)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(264, 192)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(280, 245)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Button1})
        Me.Name = "Form1"
        Me.Text = "Function Overloading Demo"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.AppendText(CountFiles(1000, 100000) & " files with size between 1KB and 100KB" & vbCrLf)
        TextBox1.AppendText(CountFiles(#1/1/2001#, #12/31/2001#) & " files created in 2001" & vbCrLf)
        TextBox1.AppendText(CountFiles(".BMP") & " BMP files" & vbCrLf)
        TextBox1.AppendText(CountFiles(1000, 100000, ".EXE") & " EXE files between 1 and 100 KB" & vbCrLf)
        TextBox1.AppendText(CountFiles(#1/1/2000#, #12/31/2001#, ".EXE") & " EXE files created in 2000 and 2001")
    End Sub

    Overloads Function CountFiles(ByVal minSize As Integer, ByVal maxSize As Integer) As Integer
        Console.WriteLine("You've requested the " & _
                            " files between " & minSize & _
                            " and " & maxSize & " bytes")
        Dim files() As String
        files = System.IO.Directory.GetFiles("C:\WINNT")
        Dim i As Integer
        Dim fileCount As Integer
        For i = 0 To files.GetUpperBound(0)
            Dim FI As New System.IO.FileInfo(files(i))
            If FI.Length >= minSize And FI.Length <= maxSize Then
                fileCount = fileCount + 1
            End If
        Next
        CountFiles = fileCount
    End Function

    Overloads Function CountFiles(ByVal fromDate As Date, ByVal toDate As Date) As Integer
        Console.WriteLine("You've requested the count of " & _
                            " files created from " & fromDate & _
                            " to " & toDate)
        Dim files() As String
        files = System.IO.Directory.GetFiles("C:\WINNT")
        Dim i As Integer
        Dim fileCount As Integer
        For i = 0 To files.GetUpperBound(0)
            Dim FI As New System.IO.FileInfo(files(i))
            If FI.CreationTime.Date >= fromDate And FI.CreationTime.Date <= toDate Then
                fileCount = fileCount + 1
            End If
        Next
        CountFiles = fileCount
    End Function

    Overloads Function CountFiles(ByVal type As String) As Integer
        Console.WriteLine("You've requested the " & type & " files")
        Dim files() As String
        files = System.IO.Directory.GetFiles("C:\WINNT")
        Dim i As Integer
        Dim fileCount As Integer
        For i = 0 To files.GetUpperBound(0)
            Dim FI As New System.IO.FileInfo(files(i))
            If FI.Extension = type Then
                fileCount = fileCount + 1
            End If
        Next
        CountFiles = fileCount
    End Function

    Overloads Function CountFiles(ByVal minSize As Integer, ByVal maxSize As Integer, ByVal type As String) As Integer
        Console.WriteLine("You've requested the " & type & _
                            " files between " & minSize & _
                            " and " & maxSize & " bytes")
        Dim files() As String
        files = System.IO.Directory.GetFiles("C:\WINNT")
        Dim i As Integer
        Dim fileCount As Integer
        For i = 0 To files.GetUpperBound(0)
            Dim FI As New System.IO.FileInfo(files(i))
            If FI.Length >= minSize And FI.Length <= maxSize And FI.Extension = type Then
                fileCount = fileCount + 1
            End If
        Next
        CountFiles = fileCount
    End Function

    Overloads Function CountFiles(ByVal fromDate As Date, ByVal toDate As Date, ByVal type As String) As Integer
        Console.WriteLine("You've requested the " & type & _
                            " files created from " & fromDate & _
                            " to " & toDate)
        Dim files() As String
        files = System.IO.Directory.GetFiles("C:\WINNT")
        Dim i As Integer
        Dim fileCount As Integer
        For i = 0 To files.GetUpperBound(0)
            Dim FI As New System.IO.FileInfo(files(i))
            If FI.CreationTime.Date >= fromDate And FI.CreationTime.Date <= toDate And FI.Extension = type Then
                fileCount = fileCount + 1
            End If
        Next
        CountFiles = fileCount
    End Function
End Class

⌨️ 快捷键说明

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