VB.Net Argument Not Specified For Parameter Error

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. The code is shown below. I get the following error: "Argument not specified for parameter ‘AFileName’ of ‘Public Sub OpenFile(AFileName As String)’." Please help me resolve the error.

The following line causes the error (line 6 in Public Class Form1):
cmd.OpenFile()

Open in new window


Full Code:
Public Class Commands
    Public Sub OpenFile(ByVal AFileName As String)
        Dim psi As New ProcessStartInfo()
        psi.UseShellExecute = True
        psi.FileName = AFileName
        Process.Start(psi)
    End Sub
End Class

Open in new window


Public Class Form1
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If radPDF1.Checked = True Then
            Dim fileName As String
            Dim cmd As New Commands
            cmd.OpenFile()
            If radPDF1.Checked = True Then
                fileName = "c:\test_3\johnson.pdf"
            Else
                fileName = "c:\test_3\ross.pdf"
            End If
        End If
    End Sub
End Class

Open in new window


The following code runs without any errors.
Public Class Form1
    Public Sub OpenFile(ByVal AFileName As String)
        Dim psi As New ProcessStartInfo()
        psi.UseShellExecute = True
        psi.FileName = AFileName
        Process.Start(psi)
    End Sub

Open in new window


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

        Dim fileName As String
        If radPDF1.Checked = True Then
            fileName = "c:\test_3\johnson.pdf"
        Else
            fileName = "c:\test_3\ross.pdf"
        End If
        OpenFile(fileName)
    End Sub

Open in new window

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.

NorieAnalyst Assistant Commented:
Try this.
Public Class Form1
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If radPDF1.Checked = True Then
            Dim fileName As String
            Dim cmd As New Commands
            
            If radPDF1.Checked = True Then
                fileName = "c:\test_3\johnson.pdf"
            Else
                fileName = "c:\test_3\ross.pdf"
            End If
        End If
        cmd.OpenFile(fileName)
    End Sub

Open in new window

0
Mark01Author Commented:
I get the following errors:
(1)
Name 'cmd' is not declared.
(2)
Name 'fileName' is not declared.
0
NorieAnalyst Assistant Commented:
You should declare cmd and filename outside the If statement and I think you need to rethink the logic.
    Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
        Dim fileName As String = ""
        Dim cmd As New Commands


        If radPDF1.Checked = True Then
            fileName = "c:\test_3\johnson.pdf"
        ElseIf radPDF2.Checked = True Then
            fileName = "c:\test_3\ross.pdf"
        End If

        cmd.OpenFile(fileName)

    End Sub

Open in new window

Note, if there are only 2 radio buttons the ElseIf isn't really needed.
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:
Moderator: How do I award points?
0
Mark01Author Commented:
No more errors! Thank you, Norie.
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.