Link to home
Start Free TrialLog in
Avatar of Mark01
Mark01Flag for United States of America

asked on

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

Avatar of Norie
Norie

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

Avatar of Mark01

ASKER

I get the following errors:
(1)
Name 'cmd' is not declared.
(2)
Name 'fileName' is not declared.
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark01

ASKER

Moderator: How do I award points?
Avatar of Mark01

ASKER

No more errors! Thank you, Norie.