Results 1 to 5 of 5

Thread: Textbox changes and Checkbox.Checked

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    5

    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

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    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.

  3. #3
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    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)

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    5

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    5

    Re: Textbox changes and Checkbox.Checked

    Quote Originally Posted by Delaney View Post
    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
  •  



Click Here to Expand Forum to Full Width