📄 textfiles.bas
字号:
Attribute VB_Name = "TextFiles"
Function OpenTextFile(xPath As String) As String
Dim fileNum As Integer, fileBuffer As String, tempBuffer As String
If Exists(xPath) = False Then OpenTextFile = "BAD PATH": Exit Function
fileNum = FreeFile() 'Set fileNum to available file number
Open xPath For Input As #fileNum 'Open file
Do While Not EOF(fileNum): DoEvents 'Set up read loop
Line Input #fileNum, tempBuffer 'Read data
fileBuffer = fileBuffer & tempBuffer & vbCrLf 'Concatenate
Loop
Close #fileNum 'Close file
OpenTextFile = fileBuffer 'Return contents of file
End Function
Public Function Exists(fizile As String) As Boolean
On Error Resume Next
If Dir(fizile) = "" Then
Exists = False
Else
Exists = True
End If
End Function
Function SaveTextFile(xPath As String, xData As String)
Dim fileNum As Integer
On Error GoTo Err:
fileNum = FreeFile() 'Set fileNum to available file number
Open xPath For Output As #fileNum 'Open file
Print #fileNum, xData 'Write data
Close #fileNum 'Close File
Exit Function
Err:
Exit Function
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -