Hi,

I am trying to add extra function to a small app that I have made and part of incorporating this is to use radio buttons.

Basically a user has to choose between 1 of 2 radio buttons and then press a normal button.

I am having trouble trying to figure out how to check which radio button was chosen when the normal button is pressed.

I think that I need a case statement but can't get my head around it.

Below is a sample of the code used in the normal button press:-

void Button1Click(object sender, EventArgs e)
		{
			if (Input.Text == "") {MessageBox.Show("You have to enter the Flickr Image Link into the Input box");}
			if (Input.Text != "") {
				String S1 = Input.Text.Replace("\"","");
				String S2 = S1.Replace("<a href","[url");
				String S3 = S2.Replace(" ","");
				int S4 = S3.IndexOf("title");
				int S5 = S3.IndexOf(">");
				String S6 = S3.Remove(S4,(S5-S4)+9);
				String S7 = S6.Insert(S4,"][img]");
				int S8 = S7.IndexOf("width");
				int S9 = S7.IndexOf("a>");
				String S10 = S7.Remove(S8,(S9-S8)+2);
				String S11 = S10.Insert(S8,"[/img][/url]");
				Output.Text = S11;
		}
	}

you see, I would like to run this code only if 1 particular radio button is chosen and run a slightly modified form of this if the other radio button is chosen.

Any pointers would be appreciated.

Regards..,

MT

Recommended Answers

All 5 Replies

Use RadioButton.Checked Property.

Use RadioButton.Checked Property.

Hi,

thanks for replying, that is the one thing that I do understand, it is how to achieve the case statement that is really puzzling me.

My 2 radio buttons are; radioReg and radioPan, and when the button is pressed it needs to check which radio button is checked and then execute the required piece of code, i.e.

if radioReg.Checked then:-

if (Input.Text == "") {MessageBox.Show("You have to enter the Flickr Image Link into the Input box");}
			if (Input.Text != "") {
				String S1 = Input.Text.Replace("\"","");
				String S2 = S1.Replace("<a href","[url");
				String S3 = S2.Replace(" ","");
				int S4 = S3.IndexOf("title");
				int S5 = S3.IndexOf(">");
				String S6 = S3.Remove(S4,(S5-S4)+9);
				String S7 = S6.Insert(S4,"][img=800x640]");
				int S8 = S7.IndexOf("width");
				int S9 = S7.IndexOf("a>");
				String S10 = S7.Remove(S8,(S9-S8)+2);
				String S11 = S10.Insert(S8,"[/img][/url]");
				Output.Text = S11;
		}

if radioPan.Checked then:-

if (Input.Text == "") {MessageBox.Show("You have to enter the Flickr Image Link into the Input box");}
			if (Input.Text != "") {
				String S1 = Input.Text.Replace("\"","");
				String S2 = S1.Replace("<a href","[url");
				String S3 = S2.Replace(" ","");
				int S4 = S3.IndexOf("title");
				int S5 = S3.IndexOf(">");
				String S6 = S3.Remove(S4,(S5-S4)+9);
				String S7 = S6.Insert(S4,"][img=1024x800]");
				int S8 = S7.IndexOf("width");
				int S9 = S7.IndexOf("a>");
				String S10 = S7.Remove(S8,(S9-S8)+2);
				String S11 = S10.Insert(S8,"[/img][/url]");
				Output.Text = S11;
		}

it is how to code the statement where it looks to see which radio button is checked and then proceeds to execute the correct procedure and also how to display an error message if the user presses the button before choosing a radio button option that I am struggling with.

I have searched the internet on the use of case statements and they show using a switch, which I can't understand how to use.

Regards..,

MT

I think that you are looking something like this:

Select Case RadioButton1.Checked
            Case True
                 //Do Something
            Case False
                //Do something else
        End Select

Hope i helped :)

commented: Thanks +1

I think that you are looking something like this:

Select Case RadioButton1.Checked
            Case True
                 //Do Something
            Case False
                //Do something else
        End Select

Hope i helped :)

That's it thank you, I had a bit of brain feeze.
;)

No problem mate, a programmer's life is all about brain freezes :p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.