今天的代码是DOS的回显,E的代码就不附了,E实现DOS回显需要用到八个API,定义三个新的数据类型,三十一行代码,已经脱离初级代码范畴了 VS2008的:Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("请输入要执行的命令")
ElseIf TextBox1.Text <> "" Then
On Error Resume Next
Shell("cmd.exe /c " & TextBox1.Text & ">C:\doshx.txt", AppWinStyle.Hide)
Dim FileName As String
FileName = "C:\doshx.txt"
Dim Fs As New System.IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim Sr As New System.IO.StreamReader(Fs, System.Text.Encoding.GetEncoding("gb2312"))
For I = 1 To 1000
TextBox2.Text = (Sr.ReadToEnd.ToString & ControlChars.CrLf)
Fs.Close()
Sr.Close()
Next
End If
Kill("C:\doshx.txt")
End Sub
End Class
控件:两个Textbox,一个Button,TEXTBOX1用来输入代码,TEXTBOX2用来显示回显 VB6.0的:控件:一个Listbox,一个Textbox,一个Button,Listbox用来回显,Textbox用来输入指令Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
N = Shell("cmd.exe /c " & Text1.Text & " > C:\dos.txt", vbHide)
On Error Resume Next
For i = 1 To 100
List1.Clear
Open "c:\dos.txt" For Input As #1
If Err.Number = 0 Then
While Not EOF(1)
Line Input #1, N
If Trim(N) <> "" Then List1.AddItem N
Wend
End If
Close #1
Err.Clear
DoEvents
Sleep 200
Next i
Kill "c:\dos.txt"
End Sub 最近正在考虑要不要弄个VB入门级教程