-
May 16th, 2013, 09:57 AM
#1
Thread Starter
Member
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
-
May 16th, 2013, 10:09 AM
#2
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.
-
May 16th, 2013, 10:15 AM
#3
Thread Starter
Member
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.
-
May 16th, 2013, 10:36 AM
#4
Re: Is there any way to make this smaller or simpler?
Can you describe what problem that code is meant to solve ?
-
May 17th, 2013, 05:15 AM
#5
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.
-
May 17th, 2013, 05:33 AM
#6
Re: Is there any way to make this smaller or simpler?
Think about your duplication...
vb Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.TextBox1.Text.Trim = String.Empty Then MessageBox.Show("Box contains no characters.") Exit Sub End If Dim message As String = Nothing Select Case True Case Me.RadioButton1.Checked AndAlso Me.RadioButton18.Checked : message = "glow2:wave2" Case Me.RadioButton12.Checked AndAlso Me.RadioButton14.Checked : message = "glow3:scroll" Case Me.RadioButton12.Checked AndAlso Me.RadioButton15.Checked : message = "glow3:shake" Case Me.RadioButton12.Checked AndAlso Me.RadioButton16.Checked : message = "glow3:slide" End Select Dim pattern As String = String.Format("{0}:{1}", message, Me.TextBox1.Text) Me.ListBox1.Items.Add(pattern) End Sub 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|