Enter topic text here.
Option Compare Database
'单参数写入
Public Function gf_Write_1()
Dim strPath As String
strPath = CurrentProject.Path & "\1.txt"
Open strPath For Output As #1 '打开文件1.txt
Print #1, "你好"
' Write #1, "你好"
Close #1 '关闭文件1.txt
Shell "notepad.exe " & strPath, vbNormalFocus
End Function
'多参数写入
Public Function gf_Write_2()
Dim a$, b$, c$
a = "123": b = "ABC": c = "你好哦"
Dim strPath As String
strPath = CurrentProject.Path & "\1.txt"
Open strPath For Output As #1 '打开文件1.txt
Print #1, a & b & c
Write #1, a, b, c
Close #1
Shell "notepad.exe " & strPath, vbNormalFocus
End Function
'追加写入
Public Function gf_Write_3()
Dim strPath As String
strPath = CurrentProject.Path & "\1.txt"
Open strPath For Append As #1 '打开文件1.txt
Print #1, "你好"
Close #1 '关闭文件1.txt
Shell "notepad.exe " & strPath, vbNormalFocus
End Function
'写入九九乘法
Public Function gf_Write_4() As String
Dim strAll As String
Dim str As String
Dim i&, j&
For i = 1 To 9
For j = 1 To i
str = i & "x" & j & "=" & i * j
strAll = strAll & str & vbTab
Next
strAll = strAll & vbCrLf
Next i
Dim strPath As String
strPath = CurrentProject.Path & "\1.txt"
Open strPath For Output As #1 '打开文件1.txt
Print #1, strAll
Close #1 '关闭文件1.txt
Shell "notepad.exe " & strPath, vbNormalFocus
End Function
'写入九九乘法
Public Function gf_Write_5() As String
Dim strAll As String
Dim str As String
Dim i&, j&
Dim strPath As String
strPath = CurrentProject.Path & "\1.txt"
Open strPath For Output As #1 '打开文件1.txt
For i = 1 To 9
strAll = ""
For j = 1 To i
str = i & "x" & j & "=" & i * j
strAll = strAll & str & vbTab
Next
Print #1, strAll
Next i
Close #1 '关闭文件1.txt
Shell "notepad.exe " & strPath, vbNormalFocus
End Function