Results 1 to 6 of 6

Thread: Is there any way to make this smaller or simpler?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Is there any way to make this smaller or simpler?

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If RadioButton1.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add(TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton13.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & TextBox1.Text)
            ElseIf RadioButton1.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("scroll:" & TextBox1.Text)
            ElseIf RadioButton1.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("shake:" & TextBox1.Text)
            ElseIf RadioButton1.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("slide:" & TextBox1.Text)
            ElseIf RadioButton1.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("wave:" & TextBox1.Text)
            ElseIf RadioButton1.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("wave2:" & TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton2.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("cyan:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton3.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("green:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton4.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("purple:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton5.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("red:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton6.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("white:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton7.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash1:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton8.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash2:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton9.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("flash3:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton10.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow1:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton11.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow2:" & "wave2:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton14.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & "scroll:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton15.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & "shake:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton16.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & "slide:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton17.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & "wave:" & TextBox1.Text)
            ElseIf RadioButton12.Checked AndAlso RadioButton18.Checked AndAlso TextBox1.Text <> Nothing Then
                ListBox1.Items.Add("glow3:" & "wave2:" & TextBox1.Text)
            End If
    
            If TextBox1.Text <> Nothing Then
                RadioButton1.Checked = True
                RadioButton13.Checked = True
                TextBox1.Text = ""
                TextBox1.Select()
            Else
                MessageBox.Show("Box contains no characters.")
            End If

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Is there any way to make this smaller or simpler?

    For starters if radioButton3 and textbox1 must be said values you would check agasint these first

    Code:
    If Not Me.RadioButton13.Checked OrElse Me.TextBox1.Text.Trim = String.Empty Then
    Also note a textbox can never be nothing. Nothing would be converted to string.empty.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: Is there any way to make this smaller or simpler?

    Why can it never be nothing? That code works, it's just really long.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Is there any way to make this smaller or simpler?

    Can you describe what problem that code is meant to solve ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Is there any way to make this smaller or simpler?

    Because if a textbox was noting in terms of reference equality an exception would be thrown. When comparing it's value to nothing it's converted to string.empty. String is a special class.

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Is there any way to make this smaller or simpler?

    Think about your duplication...

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.  
    5.         If Me.TextBox1.Text.Trim = String.Empty Then
    6.             MessageBox.Show("Box contains no characters.")
    7.             Exit Sub
    8.         End If
    9.  
    10.         Dim message As String = Nothing
    11.  
    12.         Select Case True
    13.             Case Me.RadioButton1.Checked AndAlso Me.RadioButton18.Checked : message = "glow2:wave2"
    14.             Case Me.RadioButton12.Checked AndAlso Me.RadioButton14.Checked : message = "glow3:scroll"
    15.             Case Me.RadioButton12.Checked AndAlso Me.RadioButton15.Checked : message = "glow3:shake"
    16.             Case Me.RadioButton12.Checked AndAlso Me.RadioButton16.Checked : message = "glow3:slide"
    17.         End Select
    18.  
    19.         Dim pattern As String = String.Format("{0}:{1}", message, Me.TextBox1.Text)
    20.         Me.ListBox1.Items.Add(pattern)
    21.  
    22.     End Sub
    23. End Class

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