前几天论坛上有人问我时间加减运算的办法,也就是类似5:5+6:6=11:11。 于是有了代码: Dim temp_h, temp_m As Double Select Case Op Case " +" T2 = Split (TxtTime.Text, " : " ) If T2.Length = 2 Then temp_m = CDbl (T1( 1 )) + CDbl (T2( 1 )) temp_h = CDbl (T1( 0 )) + CDbl (T2( 0 )) If temp_m >= 60 And temp_m < 120 Then temp_h += 1 temp_m -= 60 TxtTime.Text = CStr (temp_h) + " : " + CStr (temp_m) ListBox1.Items.Add(TxtTime.Text) ElseIf temp_m >= 0 And temp_m < 60 Then TxtTime.Text = CStr (temp_h) + " : " + CStr (temp_m) ListBox1.Items.Add(TxtTime.Text) ElseIf temp_m >= 120 Then MsgBox ( " 分钟数错误 " ) End If Else MsgBox ( " 仅允许一个冒号 " ) Op = " " Exit Sub End If Case " -" T2 = Split (TxtTime.Text, " : " ) If T2.Length = 2 Then temp_m = CDbl (T1( 1 )) - CDbl (T2( 1 )) temp_h = CDbl (T1( 0 )) - CDbl (T2( 0 )) If temp_m < 0 And temp_m >= - 60 Then temp_h -= 1 temp_m += 60 TxtTime.Text = CStr (temp_h) + " : " + CStr (temp_m) ListBox1.Items.Add(TxtTime.Text) ElseIf temp_m >= 0 And temp_m < 60 Then TxtTime.Text = CStr (temp_h) + " : " + CStr (temp_m) ListBox1.Items.Add(TxtTime.Text) ElseIf temp_m <= - 120 Then MsgBox ( " 分钟数错误 " ) End If Else MsgBox ( " 仅允许一个冒号 " ) Op = " " Exit Sub End If Case " " Exit Sub End Select 不过有了新问题,类似7:85这样的非标准时间不能算,于是将加减代码换掉。可是新的问题又来了,他们想一次输入数据类似1:1+2:2+3:3= 一次计算。我有想到了原来写的一个表达式解析类。这个实在太复杂,正则表达式应该ok。徘徊中~~~ 转载于:https://www.cnblogs.com/blaze/archive/2004/10/16/53063.html