Not a member of 'System.Windows.Forms.GroupBox Error -- VB.Net

I am trying to work with two radio buttons in a simple VB.net app that allows a user to select and open a PDF using the Process object. One PDF will be assigned to each radio button. Please help make the app fully functional. RadioButton 2 does not work and I get an "Value' is not a member of 'System.Windows.Forms.GroupBox" error.

Here is the code:
    Private Sub OpenFile(ByVal AFileName As String)
        Dim psi As New ProcessStartInfo()

        psi.UseShellExecute = True
        psi.FileName = AFileName
        Process.Start(psi)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If RadioButton1.Checked = True Then
            Dim fileName As String
            ' Dim test As String
            Dim test As Integer
            test = GroupBox1.Value
            Select Case test
                Case 1
                    fileName = "C:\test_3\johnson.pdf"
                Case 2
                    fileName = "C:\test_3\Ross.pdf"
            End Select
            MessageBox.Show("File name is: " + fileName)
            OpenFile(fileName)
        End If
    End Sub

Open in new window

Mark01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark01Author Commented:
Here are images of the error and the form.
 ErrorThe form
0
it_saigeDeveloperCommented:
The simple solution is to get the checked radio button from the controls in the group box; e.g. -

Form1.vb -
Public Class Form1
	Private Sub OnClick(sender As Object, e As EventArgs) Handles Button1.Click
		If TypeOf sender Is Button Then
			Dim btn = CType(sender, Button)
			If (btn.Equals(Button1)) Then
				Dim selected = (From control In GroupBox1.Controls
								Where TypeOf control Is RadioButton _
								AndAlso CType(control, RadioButton).Checked
								Select CType(control, RadioButton)).SingleOrDefault()
				If selected IsNot Nothing Then
					MessageBox.Show(String.Format("{0} is checked with; use the Text value - {1}", selected.Name, selected.Text))
				End If
			End If
		End If
	End Sub
End Class

Open in new window


Form1.Designer -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
	Inherits System.Windows.Forms.Form

	'Form overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
		Try
			If disposing AndAlso components IsNot Nothing Then
				components.Dispose()
			End If
		Finally
			MyBase.Dispose(disposing)
		End Try
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _
	Private Sub InitializeComponent()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.Button1 = New System.Windows.Forms.Button()
		Me.RadioButton1 = New System.Windows.Forms.RadioButton()
		Me.RadioButton2 = New System.Windows.Forms.RadioButton()
		Me.GroupBox1.SuspendLayout()
		Me.SuspendLayout()
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.Add(Me.RadioButton2)
		Me.GroupBox1.Controls.Add(Me.RadioButton1)
		Me.GroupBox1.Location = New System.Drawing.Point(13, 13)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(259, 82)
		Me.GroupBox1.TabIndex = 0
		Me.GroupBox1.TabStop = False
		'
		'Button1
		'
		Me.Button1.Location = New System.Drawing.Point(197, 101)
		Me.Button1.Name = "Button1"
		Me.Button1.Size = New System.Drawing.Size(75, 23)
		Me.Button1.TabIndex = 1
		Me.Button1.Text = "Button1"
		Me.Button1.UseVisualStyleBackColor = True
		'
		'RadioButton1
		'
		Me.RadioButton1.AutoSize = True
		Me.RadioButton1.Location = New System.Drawing.Point(7, 20)
		Me.RadioButton1.Name = "RadioButton1"
		Me.RadioButton1.Size = New System.Drawing.Size(128, 17)
		Me.RadioButton1.TabIndex = 0
		Me.RadioButton1.TabStop = True
		Me.RadioButton1.Text = "c:\text_3\johnson.pdf"
		Me.RadioButton1.UseVisualStyleBackColor = True
		'
		'RadioButton2
		'
		Me.RadioButton2.AutoSize = True
		Me.RadioButton2.Location = New System.Drawing.Point(7, 43)
		Me.RadioButton2.Name = "RadioButton2"
		Me.RadioButton2.Size = New System.Drawing.Size(110, 17)
		Me.RadioButton2.TabIndex = 1
		Me.RadioButton2.TabStop = True
		Me.RadioButton2.Text = "c:\test_3\ross.pdf"
		Me.RadioButton2.UseVisualStyleBackColor = True
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(284, 138)
		Me.Controls.Add(Me.Button1)
		Me.Controls.Add(Me.GroupBox1)
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.GroupBox1.ResumeLayout(False)
		Me.GroupBox1.PerformLayout()
		Me.ResumeLayout(False)

	End Sub

	Friend WithEvents GroupBox1 As GroupBox
	Friend WithEvents RadioButton2 As RadioButton
	Friend WithEvents RadioButton1 As RadioButton
	Friend WithEvents Button1 As Button
End Class

Open in new window

Which produces the following output -
Capture.PNGCapture.PNG
-saige-
0
Mark01Author Commented:
Thank you for the code, it_saige. But I am a beginner and I'm confused by the code. When I add the code to the existing app, errors occur. Wouldn't it be easy to just modify the existing code to make app function properly?
0
it_saigeDeveloperCommented:
To make your code work you only need to do the following:
	Private Sub OpenFile(ByVal AFileName As String)
		Dim psi As New ProcessStartInfo()

		psi.UseShellExecute = True
		psi.FileName = AFileName
		Process.Start(psi)
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim fileName As String
		If RadioButton1.Checked = True Then
			fileName = "c:\test_3\johnson.pdf"
		Else
			fileName = "c:\test_3\ross.pdf"
		End If
		MessageBox.Show("File name is: " + fileName)
		OpenFile(fileName)
	End Sub

Open in new window


-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark01Author Commented:
It works. Thank you, it_saige. Now I can begin to work with a simple app and modify it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.