By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Can a radio button have more than 1 function? At the top of my form is a textbox tha

P: 1
Can a radio button have more than 1 function? At the top of my form is a textbox that the user will enter their name. When a radio button is selected, a corresponding picture will show up. I also need a message to show up below at will display a message: It will be [choice of:sunny, snowy, rainy, cloudy - depending on which radio button is selected] weather today, [name entered]. I was thinking that I could do separate text boxes for the [sunny, snowy, cloudy, rainy] and the [name box], but how do I make them transfer their text to the corresponding text boxes?


Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
  3.     End Sub
  4.  
  5.     Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
  6.         If Me.RadioButton1.Checked = True Then
  7.             Me.PictureBox1.Visible = True And
  8.             Me.PictureBox2.Visible = False
  9.             Me.PictureBox3.Visible = False
  10.             Me.PictureBox4.Visible = False
  11.         End If
  12.     End Sub
  13.     Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
  14.         If Me.RadioButton2.Checked = True Then
  15.             Me.PictureBox2.Visible = True
  16.             Me.PictureBox1.Visible = False
  17.             Me.PictureBox3.Visible = False
  18.             Me.PictureBox4.Visible = False
  19.         End If
  20.     End Sub
  21.  
  22.     Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
  23.         If Me.RadioButton3.Checked = True Then
  24.             Me.PictureBox3.Visible = True
  25.             Me.PictureBox1.Visible = False
  26.             Me.PictureBox2.Visible = False
  27.             Me.PictureBox4.Visible = False
  28.         End If
  29.     End Sub
  30.  
  31.     Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
  32.         If Me.RadioButton4.Checked = True Then
  33.             Me.PictureBox4.Visible = True
  34.             Me.PictureBox1.Visible = False
  35.             Me.PictureBox2.Visible = False
  36.             Me.PictureBox3.Visible = False
  37.         End If
  38.     End Sub
  39.     Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles ButtonExit.Click
  40.         Close()
  41.     End Sub
  42.     Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles SSRC.TextChanged
  43.     End Sub
  44. End Class
Sep 20 '15 #1
Share this Question
Share on Google+
1 Reply


Seth Schrock
Expert 2.5K+
P: 2,932
Remove the "And" at the end of line 7. Also, unless there is other formatting on your textboxes, it would probably be easiest to just have one textbox and change its text.
Expand|Select|Wrap|Line Numbers
  1. Me.Textbox_Name.Text = "Sunny"
Just change the name of the textbox and then put it in the appropriate radio button's code. For the other options, just change the text.
Sep 21 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.