发布网友 发布时间:2023-07-22 14:17
共2个回答
热心网友 时间:2023-09-18 00:13
添加下图控件,并拖到窗体上。
Private Sub Command1_Click()
Dim ReadStr As String
Text1.Text = ""
CommonDialog1.Filter = "文本文件(*.Txt)|*.txt"
CommonDialog1.ShowOpen
CommonDialog1.Flags = &H8
If CommonDialog1.FileName = "" Then Exit Sub
Text1.Text =CommonDialog1.FileName
End Sub
如需要将txt文件显示到文本框中,可用下面的代码:
Private Sub Command1_Click()
Dim ReadStr As String
Text1.Text = ""
CommonDialog1.Filter = "文本文件(*.Txt)|*.txt"
CommonDialog1.ShowOpen
CommonDialog1.Flags = &H8
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Input #1, ReadStr
Text1.Text = Text1.Text + ReadStr + vbCrLf
DoEvents
Loop
Close #1
CommonDialog1.FileName = ""
End Sub
追问怎么添加控件呢???追答
右键——部件
Private Sub Command1_Click()
Text1.Text = ""
CommonDialog1.Filter = "文本文件(*.Txt)|*.txt"
CommonDialog1.ShowOpen
CommonDialog1.Flags = &H8
If CommonDialog1.FileName = "" Then Exit Sub
Text1.Text =CommonDialog1.FileName
End Sub
如需要将txt文件显示到文本框中,可用下面的代码:
Private Sub Command1_Click()
Dim ReadStr As String
Text1.Text = ""
CommonDialog1.Filter = "文本文件(*.Txt)|*.txt"
CommonDialog1.ShowOpen
CommonDialog1.Flags = &H8
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Input #1, ReadStr
Text1.Text = Text1.Text + ReadStr + vbCrLf
DoEvents
Loop
Close #1
CommonDialog1.FileName = ""
End Sub
热心网友 时间:2023-09-18 00:14
Private Sub Command1_Click()