vb.net微秒 vbnet msdn

VB.net 中如何将秒数转换为分钟或者小时假设你得到 N 秒
那么,一个小时就是 3600 秒,一分钟就是 60 秒,我们就可以这样子分割出来 :
小时 hour = N / 3600;
分钟 minute = ( N - ( hour * 3600 ) ) / 60;
秒 second = N - ( hour * 3600minute * 60 );
然后自己按照 hour : minute : second 的格式打印出来就行了。
VB.net 如何设定准确的1秒时间?form 的load事件中加一句:timer1.interval=1000
在一个按钮里面加入一句触发timer事件开始计时的代码:
timer1.enabled=true
timer的tick事件中加入这么两句:
textbox1.backcolor=color.red
timer1.enabled=false
高精度计时器可以实现,但是不是用vb.net提供的Timer控件,这个控件精度较低,只能用多线程循环检测时间 , 通过调用系统函数Environment.TickCount获取微秒级的时间:
sub threadloop
dim s as integer '保存上次调用函数的时间
do while true
if Environment.TickCount - s = 50 then'隔50微妙调用一次函数
s=Environment.TickCount
call xxx'调用外部函数
end if
loop
end sub
上面的函数放在多线程中运行
用VB.NET设计一个以秒为基本单位的表 , 并且显示在窗体上的步骤 , 并且给出关键代码是我以前自己设计的用来测试自己点钞速度用的,希望是你需要的
以下是窗体的全部代码
Public Class Form1
Dim StartFlag As Boolean = False
Dim secon As Integer
Dim minut As Integer
'空格
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Space Then
If StartFlag Then
StartFlag = False
Timer1.Enabled = False
If Val(Strings.Right(Label1.Text, 2))10 And Val(Strings.Right(Label1.Text, 2)) = 0 Then secon = 0 : minut = 0 : Label1.Text = "00:00" : Exit Sub
ListBox1.Items.Add(Label1.Text.ToString)
ListBox1.SelectedItem = ListBox1.Items.Count - 1
Label1.Focus()
Button1.Enabled = True
Label1.Text = "00:00"
secon = 0
minut = 0
Else
StartFlag = True
Timer1.Enabled = True
End If
End If
End Sub
'加载
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Clear()
Label1.Text = "00:00"
Button1.Enabled = False
secon = 0
minut = 0
Label1.Focus()
End Sub
'清空
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = False
ListBox1.Items.Clear()
Label1.Focus()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
secon= 1
If secon = 60 Then
secon = 0
minut= 1
End If
Dim seconStr As String = secon
If seconStr.Length = 1 Then seconStr = "0"seconStr
Dim minutStr As String = minut
If minutStr.Length = 1 Then minutStr = "0"minutStr
Label1.Text = minutStr":"seconStr
Label1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SeconSun As Integer
If ListBox1.Items.Count0 Then
For i = 0 To ListBox1.Items.Count - 1
Dim TemStr As String = ListBox1.Items.Item(i).ToString
Dim TemInt1 As Integer = Val(Strings.Right(TemStr, 2))
Dim TemInt2 As Integer = Val(Strings.Left(TemStr, 2))
【vb.net微秒 vbnet msdn】Debug.Print(TemInt1.ToString)
Debug.Print(TemInt2.ToString)
SeconSun= TemInt1TemInt2 * 60
Debug.Print(SeconSun.ToString)
Next
TextBox1.Text = (SeconSun / ListBox1.Items.Count).ToString"秒"
End If
Label1.Focus()
End Sub
End Class
vb.net微秒的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet msdn、vb.net微秒的信息别忘了在本站进行查找喔 。

    推荐阅读