Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Net我想在函数中修复的东西-秒表_Vb.net_Stopwatch - Fatal编程技术网

Vb.net Net我想在函数中修复的东西-秒表

Vb.net Net我想在函数中修复的东西-秒表,vb.net,stopwatch,Vb.net,Stopwatch,我创建了将时间字符串(“hh\:mm\:ss\,fff”-例如:“00:00:00100”)转换为部分的函数 strTime=“00:00:00100”= hint=0 mint=0 secint=0 毫秒int=100 职能: 例子: 功能正常, 但是当运行应用程序的函数被阻塞时,直到函数返回true 为什么会这样?您需要做的就是这样: Dim time As Date = DateTime.ParseExact("00:01:02,123", "hh:mm:ss,ff

我创建了将时间字符串(“hh\:mm\:ss\,fff”-例如:“00:00:00100”)转换为部分的函数
strTime=“00:00:00100”=
hint=0
mint=0
secint=0
毫秒int=100


职能:



例子:

功能正常,
但是当运行应用程序的函数被阻塞时,直到函数返回true

为什么会这样?

您需要做的就是这样:

    Dim time As Date = DateTime.ParseExact("00:01:02,123", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim h As Integer = time.Hour
    Dim m As Integer = time.Minute
    Dim sec As Integer = time.Second
    Dim millisec As Integer = time.Millisecond
然而,由于非常熟悉您试图实现的目标:),我怀疑您真正需要的是:

    Dim time As Date = DateTime.ParseExact("00:01:02,123", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim startTime As Date = DateTime.ParseExact("00:00:00,000", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim elapsed As TimeSpan = time - startTime
    Dim totalMilliseconds As Integer = CType(elapsed.TotalMilliseconds, Integer)
您可以用同样的方法,将每个字幕的开始和结束时间转换为总毫秒,然后以这种方式进行比较

正如其他人所指出的,在VB.NET中,只有在与VB6代码向后兼容的情况下,才能真正使用On Error Resume Next。您应该使用Try/Catch块。然而,即使在VB6中,将简历放在整个方法上方也从来没有被认为是好的做法,就像在整个方法周围放置try/catch块也被认为是坏主意一样


类似地,GoTo几乎是任何程序员所能做的最可怕的事情。您应该考虑其他选项,如循环、I/E块、将代码分解成单独的方法等,并且不惜一切代价避免Goto。

我看到“代码> Goto 语句吗?什么可以替换这个语句?这会是Windows窗体开发吗?”在这种情况下,Timer类可能会有所帮助。它有一个勾号事件,它将解决挂线问题,并有助于丢弃goto。@LarsTech,如果你仔细观察,你还会看到下一个错误恢复上的
,也许有人可以给我一个描述解决方案的例子?Tnx Bro!在这篇文章中,为什么提取evreything:)更容易,但“goto”这件事仍然很烦人:/谢谢你在问题中尝试更具体。你在进步!我试着在stopWatch.appeased.Seconds secs应用程序.Doevents()循环和计时器时执行,但它仍然不工作,以什么方式不工作?它被卡在回路中了吗?你不应该那样做。DoEvents是个坏主意,应该尽可能避免。相反,你应该像我在上一个问题中建议的那样使用一个快速计时器。是的,它在循环中停滞了,尽管秒=秒
    Dim time As Date = DateTime.ParseExact("00:01:02,123", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim h As Integer = time.Hour
    Dim m As Integer = time.Minute
    Dim sec As Integer = time.Second
    Dim millisec As Integer = time.Millisecond
    Dim time As Date = DateTime.ParseExact("00:01:02,123", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim startTime As Date = DateTime.ParseExact("00:00:00,000", "hh:mm:ss,fff", CultureInfo.InvariantCulture)
    Dim elapsed As TimeSpan = time - startTime
    Dim totalMilliseconds As Integer = CType(elapsed.TotalMilliseconds, Integer)