Cannot Start Process Error -- VB.Net

Can somebody help resolve the error that is caused by the code shown below? I get a "cannot start process because a file name has not been provided" error.

The following warnings were received: "Warning 1 Variable 'test' is used before it has been assigned a value. A null reference exception could result at runtime."
"Warning 2 Variable 'fileName' is used before it has been assigned a value. A null reference exception could result at runtime."

The screenshots show the errors and warnings.
    Private Sub OpenFile(ByVal AFileName As String)
        'EE Version 1 without error code
        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
        'ee
        If RadioButton1.Checked = True Then
            Dim fileName As String
            Dim test As String

            Select Case test
                Case 1
                    fileName = "C:\test_3\johnson.pdf"
                Case 2
                    fileName = "C:\test_3\Ross.pdf"
            End Select

            OpenFile(fileName)
        End If
    End Sub

Open in new window

ErrorWarnings
Mark01Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

AndyAinscowFreelance programmer / ConsultantCommented:
I bet you do not a file name in the message box.  If you do not then the variable 'test' contains some other value than either 1 or 2

 
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'ee
        If RadioButton1.Checked = True Then
            Dim fileName As String
            Dim test As String

            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
0
AndyAinscowFreelance programmer / ConsultantCommented:
The solution is simple - assign the value you want to the variable test
0
Mark01Author Commented:
Yes, the message box does not contain a file name. Can you provide some sample code to assign the value you want to the variable test? I am a beginner and will use this app to learn.
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

AndyAinscowFreelance programmer / ConsultantCommented:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'ee
        If RadioButton1.Checked = True Then
            Dim fileName As String
           Dim test As Integer
test = 1
           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
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:
The error is gone but the only the johnson.pdf will open when RadioButton 1 is clicked. RadioButton 2 does not work. Doesn't the sub OpenFile need to be called in order for both radio buttons to function?

Full 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 = 1
            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

The form
0
AndyAinscowFreelance programmer / ConsultantCommented:
Experts exchange really likes a question - answer set.  Your original question was answered.

Concerning your follow up with radio buttons you probably want to replace
            test = 1
with something like
            test = GroupBox1.Value

If it doesn't work then please close this question and open a new question about linking radio buttons to variables.  (I'm not going to get back until tomorrow at the earliest now).
0
Mark01Author Commented:
Thank you, Andy.
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.