-
Feb 23rd, 2021, 04:18 PM
#1
Thread Starter
New Member
Textbox changes and Checkbox.Checked
Gud evening members , this is my second post
i did a Duct size Calculator program for me in VB.net 2010,
the Calculator is working
just need simpilyfication of this code if some one help to reduce this code simple very helpful
this is the code:
Code:
'When Flow Changed
Private Sub txtQ_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtQ.TextChanged
If CheckBox1.Checked And CheckBox2.Checked Then
Airflow_HeadLoss()
Else
End If
If CheckBox1.Checked And CheckBox3.Checked Then
Airflow_Velocity()
Else
End If
If CheckBox1.Checked And CheckBox4.Checked Then
Airflow_Diameter()
Else
End If
End Sub
'When Headloss Changed
Private Sub txtHf_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtHf.TextChanged
If CheckBox1.Checked And CheckBox2.Checked Then
Airflow_HeadLoss()
Else
End If
If CheckBox2.Checked And CheckBox3.Checked Then
Headloss_Velocity()
Else
End If
If CheckBox2.Checked And CheckBox4.Checked Then
Headloss_Diameter()
Else
End If
End Sub
'When Velocity Changed
Private Sub txtV_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtV.TextChanged
If CheckBox1.Checked And CheckBox3.Checked Then
Airflow_Velocity()
Else
End If
If CheckBox2.Checked And CheckBox3.Checked Then
Headloss_Velocity()
Else
End If
If CheckBox3.Checked And CheckBox4.Checked Then
Velocity_Diameter()
Else
End If
End Sub
'When Diameter Changed
Private Sub txtD_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtD.TextChanged
If CheckBox1.Checked And CheckBox4.Checked Then
Airflow_Diameter()
Else
End If
If CheckBox2.Checked And CheckBox4.Checked Then
Headloss_Diameter()
Else
End If
If CheckBox3.Checked And CheckBox4.Checked Then
Velocity_Diameter()
Else
End If
Duct_Size()
Duct_Data()
End Sub
-
Feb 23rd, 2021, 06:01 PM
#2
Re: Textbox changes and Checkbox.Checked
Hi rahil40,
The first and obvious changes would look like this: -
Code:
'When Flow Changed
Private Sub txtQ_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtQ.TextChanged
If CheckBox1.Checked Then
If CheckBox2.Checked Then Airflow_HeadLoss()
If CheckBox3.Checked Then Airflow_Velocity()
If CheckBox4.Checked Then Airflow_Diameter()
End If
End Sub
'When Headloss Changed
Private Sub txtHf_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtHf.TextChanged
If CheckBox2.Checked Then
If CheckBox1.Checked Then Airflow_HeadLoss()
If CheckBox3.Checked Then Headloss_Velocity()
If CheckBox4.Checked Then Headloss_Diameter()
End If
End Sub
'When Velocity Changed
Private Sub txtV_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtV.TextChanged
If CheckBox3.Checked Then
If CheckBox1.Checked Then Airflow_Velocity()
If CheckBox2.Checked Then Headloss_Velocity()
If CheckBox4.Checked Then Velocity_Diameter()
End If
End Sub
'When Diameter Changed
Private Sub txtD_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtD.TextChanged
If CheckBox4.Checked Then
If CheckBox1.CheckedThen Airflow_Diameter()
If CheckBox2.Checked Then Headloss_Diameter()
If CheckBox3.Checked Then Velocity_Diameter()
End If
Duct_Size()
Duct_Data()
End Sub
Since you're not using 'sender' or 'e' in any of these subroutines, I personally, would also remove the 'sender As System.Object, e As System.EventArgs' from all the subroutines to make for a much tidier look, but I expect there would be complaints from some quarters.
Poppa
Last edited by Poppa Mintin; Feb 23rd, 2021 at 07:52 PM.
Along with the sunshine there has to be a little rain sometime.
-
Feb 23rd, 2021, 06:10 PM
#3
Re: Textbox changes and Checkbox.Checked
first you can remove all the "else"
the first part
Code:
If CheckBox1.Checked And CheckBox2.Checked Then
Airflow_HeadLoss()
Else
End If
If CheckBox1.Checked And CheckBox3.Checked Then
Airflow_Velocity()
Else
End If
If CheckBox1.Checked And CheckBox4.Checked Then
Airflow_Diameter()
Else
End If
can be written
Code:
If CheckBox1.Checked then
if CheckBox2.Checked Then Airflow_HeadLoss()
if CheckBox3.Checked Then Airflow_Velocity()
if CheckBox4.Checked Then Airflow_Diameter()
end if
I let you do the other ones
PS : a bit slow on this one
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Feb 23rd, 2021, 11:22 PM
#4
Thread Starter
New Member
Re: Textbox changes and Checkbox.Checked
Dear, have a good day
much thanks
the code works well
i remove sender also from the event its work
thanks alot poppaAttachment 180288
-
Feb 23rd, 2021, 11:29 PM
#5
Thread Starter
New Member
Re: Textbox changes and Checkbox.Checked
Originally Posted by Delaney
first you can remove all the "else"
the first part
can be written
Code:
If CheckBox1.Checked then
if CheckBox2.Checked Then Airflow_HeadLoss()
if CheckBox3.Checked Then Airflow_Velocity()
if CheckBox4.Checked Then Airflow_Diameter()
end if
I let you do the other ones
PS : a bit slow on this one
yes brother , thanks you
as above way it works good
have any other way to solve this
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|