VB6.0如何读取TXT中的数据并求和
2个回答
展开全部
3个TextBox,点击Command1可以弹出对话框,显示三个文本框的内容并显示总和。注意:内容必须为数字。
代码如下:
Private Sub Command1_Click()
MsgBox "第一个文本框内容" & Text1.Text & ",第二个文本框内容" & Text2.Text & "第三个文本框内容" & Text3.Text & 总和 Text1.Text + Text2.Text + Text3.Text & "。"
End Sub
读取文件的话,用下面的代码:
Private Sub Command1_Click()
Dim txt1 As String, txt2 As String, txt3 As String
Open "d:\123\1.txt" For Input As #1
txt1 = Input(LOF(1), 1)
Close #1
Open "d:\123\2.txt" For Input As #1
txt2 = Input(LOF(1), 1)
Close #1
Open "d:\123\3.txt" For Input As #1
txt3 = Input(LOF(1), 1)
Close #1
MsgBox "第一个文件内容" & txt1 & " 第二个文件内容" & txt2 & " 第三个文件内容" & txt3 & "总和" & txt1 + txt2 + txt3 & "。"
End Sub
希望能帮助到你!
代码如下:
Private Sub Command1_Click()
MsgBox "第一个文本框内容" & Text1.Text & ",第二个文本框内容" & Text2.Text & "第三个文本框内容" & Text3.Text & 总和 Text1.Text + Text2.Text + Text3.Text & "。"
End Sub
读取文件的话,用下面的代码:
Private Sub Command1_Click()
Dim txt1 As String, txt2 As String, txt3 As String
Open "d:\123\1.txt" For Input As #1
txt1 = Input(LOF(1), 1)
Close #1
Open "d:\123\2.txt" For Input As #1
txt2 = Input(LOF(1), 1)
Close #1
Open "d:\123\3.txt" For Input As #1
txt3 = Input(LOF(1), 1)
Close #1
MsgBox "第一个文件内容" & txt1 & " 第二个文件内容" & txt2 & " 第三个文件内容" & txt3 & "总和" & txt1 + txt2 + txt3 & "。"
End Sub
希望能帮助到你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询