惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Vercel News
Vercel News
F
Fortinet All Blogs
月光博客
月光博客
G
Google Developers Blog
博客园 - Franky
GbyAI
GbyAI
The Cloudflare Blog
I
InfoQ
雷峰网
雷峰网
WordPress大学
WordPress大学
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 聂微东
小众软件
小众软件
腾讯CDC
B
Blog
量子位
V
V2EX
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News

博客园 - Blaze

eVC++就是eVC++啊 - Blaze - 博客园 VC++常用数据类型及其操作详解[徐兆元] From VB.NET to C# and Back Again [By Darren Neimke and Scott Mitchell ] 请不要做浮躁的人(老文了,还是转一下,共勉) 地球上最慢的网路不在巴布里亚新几内亚和尼泊尔之间,而在中国网通和电信之间! [翻译]用TcpClient建立GPRS连接 1年零2个月零25天 我回来了 .NET的Pascal--Chrome来了! Gmail疯了?50个邀请! 检举个博客园的Bug! INI配置文件的替代品-XML配置文件的操作 INI的替代品--XML配置文件读取与保存 Wallop下蛋送邀请。 从WebService的SessionID说起 Gmail下蛋了 udp的奇怪问题 webservice对"小"规模数据传输的效率问题 运动会痛苦经历 n个VB.Net C#代码转换工具
关于时间的加减计算
Blaze · 2004-10-16 · via 博客园 - Blaze

前几天论坛上有人问我时间加减运算的办法,也就是类似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。徘徊中~~~