我使用函數將時間字符串(「hh \:mm \:ss \,fff」 - 例如:「00:00:00,100」)轉換爲零件
strTime = 「00:00:00100」=
ħ INT = 0
米 INT = 0
秒 INT = 0
毫秒 INT = 100
功能:
Vb.Net我想在我的函數中修復的東西 - 秒錶
Public Function ShowInLabel(ByVal TEXT As String, ByVal time As String, ByVal startTime As Boolean) As Boolean
On Error Resume Next
Dim sss As String
sss = time
Dim start As String = StrReverse(sss)
start = StrReverse(start.Substring(0, 3))
Dim s As Integer
s = Integer.Parse(start)
Dim secstart As String = StrReverse(sss).Substring(0, 6)
secstart = StrReverse(secstart)
Dim secs As Integer = Integer.Parse(secstart.Substring(0, 2))
Dim hurs As Integer = Integer.Parse(sss.Substring(0, 2))
Dim mins As Integer = Integer.Parse(StrReverse(StrReverse(sss.Substring(0, 5)).Substring(0, 2)))
Dim stopWatch As New Stopwatch()
stopWatch.Start()
noh:
If stopWatch.Elapsed.Hours = hurs Then
GoTo yesh
Else
GoTo noh
End If
yesh:
If stopWatch.Elapsed.Minutes = mins Then
GoTo yesm
Else
GoTo yesh
End If
yesm:
If stopWatch.Elapsed.Seconds = secs Then
GoTo yess
Else
GoTo yesm
End If
yess:
If stopWatch.Elapsed.Milliseconds > s Or stopWatch.Elapsed.Milliseconds = s Then
GoTo done
Else
GoTo yess
End If
done:
If startTime = False Then
Label1.Text = ""
Else
Label1.Text = TEXT
End If
Return True
End Function
例如:
ShowInLabel("SubTitle", "00:00:00,100", True)
函數工作,
但當乳寧該應用程序的功能是Stucked 直到函數返回true
爲什麼會發生?
我看到'GOTO'語句嗎? – LarsTech
什麼可以替代這種說法? – nnm
這會發生在Windows窗體開發?在這種情況下,Timer類可能會有所幫助。它具有Tick事件,可以解決懸掛線程問題,並幫助丟棄goto。 – Jonas