我找了些代码但是不会运用多行
Private Sub Command1_Click() '写文件
writeToFile "1\123.txt", "文字"
MsgBox "写入完毕!"
End Sub
Private Function writeToFile(ByVal strFileName As String, ByVal strContent As String) As Boolean
On Error GoTo Err1
Open strFileName For Output As #1
Print #1, strContent
Close #1
writeToFile = True
Exit Function
Err1:
writeToFile = False
End Function
这个就是代码,但是是一行输入文本,我想输入多行,请高手帮助啊
VB写入文本多行写入
答案:2 悬赏:10 手机版
解决时间 2021-03-08 02:27
- 提问者网友:我没有何以琛的痴心不悔
- 2021-03-07 12:17
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-03-07 12:25
Option Explicit
Private Sub Command1_Click() '写文件
Dim strA As String, strB As String, strC As String, strN As String
strA = "第一行" '第一行
strB = "第二行" '第二行
strN = "第N行" '第N行
strC = strA & vbCrLf & strB & vbCrLf & strN 'vbCrLf 是VB回车换行符
'这句要注意,writeToFile 是有返回值的,用于判断文件是否正确完成写入操作
If writeToFile("c:\123.txt", strC) = True Then
MsgBox "写入完毕!"
Else
MsgBox "写入失败!"
End If
End Sub
Private Function writeToFile(ByVal strFileName As String, ByVal strContent As String) As Boolean
On Error GoTo Err1 '发生错误跳至Err1:
Open strFileName For Output As #1 '打开文件
Print #1, strContent
Close #1
writeToFile = True '文件正确写入时
Exit Function
Err1:
writeToFile = False '文件写入发生错误时
End Function
Private Sub Command1_Click() '写文件
Dim strA As String, strB As String, strC As String, strN As String
strA = "第一行" '第一行
strB = "第二行" '第二行
strN = "第N行" '第N行
strC = strA & vbCrLf & strB & vbCrLf & strN 'vbCrLf 是VB回车换行符
'这句要注意,writeToFile 是有返回值的,用于判断文件是否正确完成写入操作
If writeToFile("c:\123.txt", strC) = True Then
MsgBox "写入完毕!"
Else
MsgBox "写入失败!"
End If
End Sub
Private Function writeToFile(ByVal strFileName As String, ByVal strContent As String) As Boolean
On Error GoTo Err1 '发生错误跳至Err1:
Open strFileName For Output As #1 '打开文件
Print #1, strContent
Close #1
writeToFile = True '文件正确写入时
Exit Function
Err1:
writeToFile = False '文件写入发生错误时
End Function
全部回答
- 1楼网友:话散在刀尖上
- 2021-03-07 14:01
if text1.text = "" then msgbox "信息输入不完整!请验证后重新输入!!", vbokonly + vbinformation, " " elseif text2.text = "" then msgbox "信息输入不完整!请验证后重新输入!!", vbokonly + vbinformation, " "
else open "c:\program files\" & "\abc.txt" for append as #1 print #1, text1.text print print #1, text2.text print print #1, text3.text print print #1, text4.text close #1 msgbox "您提供的信息错误或网络繁忙!", vbokonly + vbinformation, " " end if filecopy ....
end sub
根据情况修改
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯