我想在我的代码中延迟1秒钟.下面是我试图延迟的代码.我认为它会轮询操作系统的日期和时间,并等到时间匹配.我有延迟的问题.我认为它不会轮询与等待时间匹配的时间,它只是坐在那里并冻结.它只会冻结我运行代码的大约5%的时间.我想知道Application.Wait以及是否有办法检查轮询时间是否大于等待时间.
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Run Code Online (Sandbox Code Playgroud) 我正在编写一个通过串口进行通信的程序.发送的所有数据都会被镜像回来.除了退格之外,一切正常.当我按下退格按钮时,我知道如何删除文本框中最后一个字符的唯一方法是使用mid函数,然后用新数据覆盖当前数据.当大量数据在richtextbox中时,它开始闪烁.我尝试过使用richtextbox.text.remove函数,但是我收到了这个错误."索引和计数必须引用字符串中的位置.参数名称:count"
RichTextBox1.Text.Remove(RichTextBox1.TextLength, 1)
Run Code Online (Sandbox Code Playgroud)
我试图在函数中抛出一些数字,但不会导致错误输出,但是没有从richtextbox中删除数据.
这是传输数据的代码
KeyCharString = e.KeyChar 'stores key being pressed into KeyCharString
Try
SerialPort1.Write(KeyCharString) 'tx data for key being pressed
Catch ex As Exception
MsgBox(ex.Message) 'Displays error if serialport1 cannot be written to
End Try
If Asc(KeyCharString) = 8 Then 'If char is a backspace remove precious character and exit sub
RichTextBox1.Text = RichTextBox1.Text.Remove(RichTextBox1.TextLength, 1)
'RichTextBox1.Text = Mid(RichTextBox1.Text, 1, RichTextBox1.TextLength - 1)'Old code used to remove the character. Causes the richtextbox to flicker when rewriting the data
Exit …Run Code Online (Sandbox Code Playgroud)