System.IO - directory location by variable

This shows in the error list, highlighting the pdfloc variable:-

Reference to a non-shared member requires an object reference.

Thanks for your help.
 
Could you post more of your code? Cannot really tell where the problem lies from just one line.
Where is the above code being executed from and where is pdfloc defined?
 
Sorry, here we go:

Code:
Imports System
Imports System.IO
Imports System.Collections

Public Class StartForm

     Create var for location
    Dim pdfloc As String
    Private Sub StartForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("On the next window select the folder containing the PDF files.")

        FolderBrowserDialog1.ShowDialog()
        If FolderBrowserDialog1.SelectedPath = FolderBrowserDialog1.SelectedPath Then
            PdfLocationLbl.Text = FolderBrowserDialog1.SelectedPath
            pdfloc = FolderBrowserDialog1.SelectedPath

        End If
    End Sub

    Private Sub createmetadatabtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createmetadatabtn.Click
        DeleteTest.Main()
    End Sub

    Public Class DeleteTest


        Public Shared Sub Main()

             Create a reference to a file.
            Dim fi As New FileInfo(pdfloc & "temp.txt")
             Actually create the file.
            Dim fs As FileStream = fi.Create()
             Close the file.
            fs.Close()
        End Sub Main

    End Class DeleteTest

End Class
 
pdfloc is declared within the StartForm class and is therefore not available from the DeleteTest class, you could either make the variable public (a bad idea), or create a read only property that returns the value of pdfloc.

Also is there a particular reason the sub is called Main? That is normally reserved for the applications entry point. You may want to create a parameter in the Main method though and pass pdfloc that way.
 
Back
Top