【发布时间】:2012-06-14 13:14:34
【问题描述】:
我制作了将时间字符串(“hh\:mm\:ss\,fff” - 例如:“00:00:00,100”)转换为零件的函数
strTime = "00:00:00,100" =
h int = 0
m int = 0
sec int = 0
毫秒 int = 100
功能:
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)
函数有效,
但是当运行应用程序的函数被卡住 Till 函数返回 true
为什么会这样?
【问题讨论】:
-
我看到
GOTO声明了吗? -
这个语句可以用什么代替?
-
会不会是Windows Form开发?在这种情况下, Timer 类可能会有所帮助。它有 Tick 事件,既可以解决挂线问题,又可以帮助丢弃 goto。
-
@LarsTech,如果你仔细看你还会看到
On Error Resume Next -
也许有人可以给我一个描述解决方案的例子?