frmcontrols.frm
来自「Visual Basic 6 大学教程的代码」· FRM 代码 · 共 182 行
FRM
182 行
VERSION 5.00
Begin VB.Form frmControls
Caption = "Fig. 14.9: Demonstrating FileSystemObject"
ClientHeight = 3405
ClientLeft = 1860
ClientTop = 2430
ClientWidth = 5385
LinkTopic = "Form1"
ScaleHeight = 3405
ScaleWidth = 5385
Begin VB.TextBox txtDisplay
Height = 1275
Left = 120
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 6
Top = 2010
Width = 5175
End
Begin VB.FileListBox filFileBox
Height = 1455
Left = 3135
TabIndex = 0
Top = 390
Width = 2160
End
Begin VB.DirListBox dirDirBox
Height = 765
Left = 135
TabIndex = 2
Top = 1080
Width = 2790
End
Begin VB.DriveListBox drvDriveBox
Height = 315
Left = 150
TabIndex = 1
Top = 405
Width = 2460
End
Begin VB.Label lblLabel
Caption = "DriveListBox:"
Height = 240
Left = 150
TabIndex = 5
Top = 180
Width = 1455
End
Begin VB.Label lblLabel2
Caption = "FileListBox:"
Height = 255
Left = 3135
TabIndex = 4
Top = 165
Width = 1650
End
Begin VB.Label lblLabel1
Caption = "DirListBox:"
Height = 330
Left = 150
TabIndex = 3
Top = 870
Width = 2775
End
Begin VB.Menu mnuFile
Caption = "File"
Begin VB.Menu mnuitmCreateFolder
Caption = "C&reate Folder"
End
Begin VB.Menu mnuitmDeleteFolder
Caption = "&Delete Folder"
End
Begin VB.Menu mnuitmExit
Caption = "E&xit"
End
End
End
Attribute VB_Name = "frmControls"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 14.9
' Demonstrating FileSystemObjects
Option Explicit ' General declaration
Dim mFileSysObj As New FileSystemObject ' General declaration
Private Sub dirDirBox_Change()
' Update the file path to the directory path
filFileBox.Path = dirDirBox.Path
End Sub
Private Sub drvDriveBox_Change()
On Error GoTo errorhandler
' Update the directory path to the drive
dirDirBox.Path = drvDriveBox.Drive
Exit Sub
errorhandler:
Dim message As String
' Check for device unavailable error
If Err.Number = 68 Then
Dim r As Integer
message = "Drive is not available."
r = MsgBox(message, vbRetryCancel + vbCritical, _
"VBHTP: Chapter 14")
' Determine where control should resume
If r = vbRetry Then
Resume
Else ' Cancel was pressed.
drvDriveBox.Drive = drvDriveBox.List(1)
Resume Next
End If
Else
Call MsgBox(Err.Description, vbOKOnly + vbExclamation)
Resume Next
End If
End Sub
Private Sub filFileBox_Click()
Call displayData ' Update TextBox
End Sub
' Programmer defined
Private Sub displayData()
txtDisplay.Text = ""
txtDisplay.Text = "GetAbsolutePathName: " & _
mFileSysObj.GetAbsolutePathName( _
filFileBox.Path) & vbNewLine & _
"GetDriveName: " & _
mFileSysObj.GetDriveName( _
filFileBox.Path) & vbNewLine & _
"GetParentFolderName: " & _
mFileSysObj.GetParentFolderName( _
filFileBox.Path) & vbNewLine & _
"GetTempName: " & mFileSysObj.GetTempName
End Sub
Private Sub mnuitmCreateFolder_Click()
Dim s As String
' Get the Folder name
s = InputBox("Enter complete path and folder name:", "CREATE")
' Test if the Folder already exists
If mFileSysObj.FolderExists(s) Then
Call MsgBox("Folder already exists! Cannot create.")
Exit Sub
End If
Call mFileSysObj.CreateFolder(s) ' Create the Folder
Call dirDirBox.Refresh ' Repaint DirListBox
End Sub
Private Sub mnuitmDeleteFolder_Click()
Dim s As String
' Get the Folder name
s = InputBox("Enter complete path and folder name:", "DELETE")
' Test if the Folder already exists
If mFileSysObj.FolderExists(s) = False Then
Call MsgBox("Folder does not exist! Cannot delete.")
Exit Sub
End If
Call mFileSysObj.DeleteFolder(s) ' Delete the Folder
Call dirDirBox.Refresh ' Repaint DirListBox
End Sub
Private Sub mnuitmExit_Click()
End ' Terminate execution
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?