I'm coming from Python to Visual Basic and it's really playing with my head. This program is intended to scan a list of directories (only have one directory so far) and see if they contain any files. If they do, their directory is added to a list (DirtyFolders) and all files in those folders will be deleted when a button is pressed.

When I try to add the folder's directory to the list it throws an exception, "Object reference not set to an instance of an object."
That might as well be Japanese as I have no clue what it is trying to tell me.

Public Class Engine
    Shared DirtyFolders As List(Of String)

    Public Shared Sub Scan()
        Dim folder = "C:\Tester"

        If HasFiles(folder) Then
            Show("Files found in " & folder)
            DirtyFolders.Add(folder) '<-- Error happens here
        Else
            Show("No files in " & folder)
        End If
    End Sub

Recommended Answers

All 3 Replies

The reference you have set to folder is incomplete.

Dim folder = "C:\Tester"

Specify Tester as in Tester.txt etc.

Just do the following, then it will have a reference set to a new List

Dim Shared DirtyFolders As New List(Of String)

Solved. Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.