vb一道读程序和一道编程序的题目 急!(高手请进~~)

1编程:设窗体上有一个DriveListBox控件Drive1,一个DirListBox控件Dir1和一个FileListBox控件File1,该窗体刚装入时,显示C盘根目录下的全部 .BAT 文件,要求在用户选择Drive1控件中的驱动器后,Dir1控件中的目录随之改变,当Dir1中的目录改变后,File1控件中的文件随之改变。请编写出相应的程序。

2读程序:设在一个窗体中已经设置了一个文本框Text1和二个命令按钮Comd1和Comd2,以及一个公共对话框CommonDialog1,且设计有下列程序,请指出程序的功能。

Option Explicit
Private Sub Comd1_Click()
Dim Lstr
Text1.Text = ""
Common Dialog1.Filter = "Text files(*.txt)|*.txt"
Common Dialog1.FilterIndex = 1
Common Dialog1.Action = 1
Open Common Dialog1.FileName For Input As #1
While Not EOF(1)
Line Input #1, Lstr
Text1.Text = Text1.Text + Lstr + Chr(13) + Chr(10)
Wend
Close #1
Comd2.Enabled = True
Comd1.Enabled = False
End Sub
Private Sub Comd2_Click()
Text1.Text = ""
Comd1.Enabled = True
Comd2.Enabled = False
End Sub
Private Sub Form_Load()
Text1.Text = ""
Comd2.Enabled = False
End Sub
读程序的题目结果请写得稍微详细些,谢谢~~
3.设在一个窗体中已设计了一组五个单选按钮Option1(0) ~ Option1(4) 和一个公共对话框ComDialog1,并有如下代码,请写出运行的结果。
Private Sub Form_Load()
Option1(4).Value = True
Option1(4).Visible = False
End Sub
Private Sub Option1_Click(Index As Integer)
Dim FileName1 As String, FileName2 As String
Select Case Index
Case 0
ComDialog1.ShowOpen
FileName1 = ComDialog1.FileName
Kill FileName1
Case 1
ComDialog1.ShowOpen
FileName1 = ComDialog1.FileName
ComDialog1.ShowSave
FileName2 = ComDialog1.FileName
FileCopy FileName1, FileName2
Kill FileName1
Case 2
ComDialog1.ShowOpen
FileName1 = ComDialog1.FileName
ComDialog1.ShowSave
FileName2 = ComDialog1.FileName
FileCopy FileName1, FileName2
Case 3
ComDialog1.ShowOpen
FileName1 = ComDialog1.FileName
FileName2 = InputBox("The New file name:", FileName1)
Name FileName1 As FileName2
End Select
Option1(4).Value = True
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
File1.Pattern = "*.bat"
Drive1.Drive = "C:"
Dir1.Path = "C:\"
End Sub

第2题:
程序启动时禁用Comd2,同时清空Text1。
在点击Comd1时,通过打开文件的通用对话框获取一个txt文件名并通过open、line input等操作读入文件内容显示在Text1中。读取完毕后启用Comd2并禁用Comd1.
点击Comd2时启用Comd1,并禁用Comd2,同时清空Text1。
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-04-14

Private Sub Command1_Click()   '-----------------第二问

Dim sline As String

On Error GoTo err

CommonDialog1.DialogTitle = "打开txt文件"

CommonDialog1.InitDir = "c:\"

CommonDialog1.Filter = "Text文件(*.txt)|*.txt;"

CommonDialog1.filename = ""

CommonDialog1.ShowOpen

Open CommonDialog1.filename For Input As #1

While Not EOF(1)

Line Input #1, sline

Text1.Text = Text1.Text & sline & vbCrLf

Wend

Close #1

err:

End Sub

Private Sub Command2_Click()

Text1.Text = ""

End Sub

Private Sub Dir1_Change()      '-------------------------第一问

File1.Path = Dir1

File1.Pattern = "*.bat"

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1

File1.Path = Dir1

End Sub

Private Sub Form_Load()

File1.Pattern = "*.bat"

End Sub

相似回答
大家正在搜