这个真不会,以前Qbasic时,有定位命令,
VB6,你输出退格键试试。
程序代码:
Option Explicit
Const STD_INPUT_HANDLE = -10&
Const STD_OUTPUT_HANDLE = -11&
Const STD_ERROR_HANDLE = -12&
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleW" (ByVal hConsoleOutput As Long, ByVal lpBuffer As Long, ByVal nNumberOfCharsToWrite As Long, ByVal lpNumberOfCharsWritten As Long, ByVal lpReserved As Long) As Long
Private Declare Function ReadConsole Lib "kernel32" Alias "ReadConsoleW" (ByVal hConsoleInput As Long, ByVal lpBufferas As Long, ByVal nNumberOfCharsToRead As Long, lpNumberOfCharsRead As Long, ByVal pInputControl As Long) As Long
Private Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long
Dim hin As Long
Dim hout As Long
Dim herr As Long
Sub Cout(s As String)
WriteConsole hout, StrPtr(s), Len(s), 0, 0
End Sub
Function Cin() As String
Dim buf As String
Dim n As Long
Dim f As Long
buf = Space(1024)
f = ReadConsole(hin, StrPtr(buf), 1024, n, 0)
Cin = Left(buf, n)
End Function
Private Sub Command1_Click()
Dim s As String
Dim n As Long
Cout "请输入定时器速度,单位毫秒:"
FlushFileBuffers hin
s = Cin
Cout s
Timer1.Interval = CInt(s)
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
AllocConsole
hin = GetStdHandle(STD_INPUT_HANDLE)
hout = GetStdHandle(STD_OUTPUT_HANDLE)
herr = GetStdHandle(STD_ERROR_HANDLE)
End Sub
Private Sub Form_Unload(Cancel As Integer)
FreeConsole
End Sub
Private Sub Timer1_Timer()
Static n As Long
n = n + 1
Cout vbCr & "进度:" & n & "% "
If n >= 100 Then
Timer1.Enabled = False
n = 0
End If
End Sub