如何使代码简短? [英] How to make the code short?
本文介绍了如何使代码简短?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何缩短代码?
Private Sub Timer2_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Timer2.Tick
how to make the code short?
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim c As Double = Val(TextBox5.Text)
Dim b As Double = Val(TextBox4.Text)
Dim a As Double = Val(TextBox6.Text)
TextBox6.Text = a + 0.01
If TextBox6.Text = 0.28 Then
TextBox4.Text = 25
TextBox5.Text = 1
End If
If TextBox6.Text = 0.56 Then
TextBox4.Text = 25 + 25
TextBox5.Text = 2
End If
If TextBox6.Text = 0.84 Then
TextBox4.Text = 75
TextBox5.Text = 3
End If
If TextBox6.Text = .84 + .28 Then
TextBox4.Text = 75+25
TextBox5.Text = 3+!
End If
ETC ......
ETC......
推荐答案
逻辑是得到当前TextBox6值的分割结果和0.28
:
伪代码:
The logic is to get the result of division of current TextBox6 value and0.28
:
Pseudo code:
Const dmod As Double = 0.28
a = TextBox6.Text
a += .1
If a > .27 Then 'it is necessary to prevent ...
TextBox4.Text = Int((a / dmod) * 25)
TextBox5.Text = Int(a / dmod)
End If
如果目标是缩短代码。也许这可能有所帮助。 (仅限算法)
If the objective is to shorten the code. perhaps this could help. (algorithm only)
// algorithm only, cant seem to remember VB as its been 14 years since i did any VB
dim baseValue as double = 0.28
dim multiplyFactor as int = 0
dim resultBase as int = 25
multiplyFactor = (int)((double)TextBox6.Text/baseValue)
TextBox4.Text = multiplyFactor * resultBase
TextBox5.Text = multiplyFactor <=3 ? multiplyFactor : "3+!"
PS 在算法中没有异常处理和正确的类型转换。
PSS 我的奖品现在在哪里:)
P.S. No exception handling and proper type conversion being done in the algo.
P.S.S. Where is my prize now :)
这篇关于如何使代码简短?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文