Click here to Skip to main content
15,883,958 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to make the code short?

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
VB
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......
Posted
Updated 25-Feb-15 21:37pm
v2
Comments
CPallini 26-Feb-15 4:07am    
I see a pattern there...
Richard MacCutchan 26-Feb-15 6:08am    
Why are you storing the values from your textboxes, but then trying to use the text strings as numbers?

The logic is to get the result of division of current TextBox6 value and 0.28:
Pseudo code:
VB
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
 
Share this answer
 
v3
Comments
ara salvador 26-Feb-15 6:49am    
i will put this code on timer...
when i start the timer

txtbox6 = .28
then the value in textbox4 and txtbox5 will change
If the objective is to shorten the code. perhaps this could help. (algorithm only)

VB
// 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+!"


P.S. No exception handling and proper type conversion being done in the algo.


P.S.S. Where is my prize now :)
 
Share this answer
 
Comments
ara salvador 26-Feb-15 6:47am    
syntax error ...



"3+!" ??
Rahul Rajat Singh 26-Feb-15 6:48am    
It is an algorithm not code. I have made the declaimer above. Your might want to make it syntactically correct before using it.
ara salvador 26-Feb-15 7:00am    
i will put this code on timer...
when i start the timer

txtbox6 = .28
then the value in textbox4 and txtbox5 will change

i will use this code on my project like gasoline station

textbox 4 is liters and textbox 5 is equal to amount of liters then thetextbox 6 is timer only

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900