Vb错误对象引用未设置为对象的实例

时间:2014-04-15 00:12:14

标签: vb.net

我在为我的程序创建更新程序时遇到问题。按下按钮时,它只是给我这个错误:

对象引用未设置为对象的实例

我有一个dll文件和一个Forms应用程序文件。

这是dll文件的代码:

Public Class Class1
Dim bit As Boolean = False

Sub bits()
    'For 32 and 64 bit decison
    If My.Computer.FileSystem.DirectoryExists("C:\Program Files(x86)") = False Then
        bit = False
    Else
        bit = True
    End If
End Sub
Sub CheckFolder(ByVal i As String)
    If i.Contains("Program Files") And bit = False Then
    ElseIf bit = True Then
        i.Replace("Program Files", "Program Files(x86)")
    Else
    End If

    If My.Computer.FileSystem.DirectoryExists(i) Then
    Else
        My.Computer.FileSystem.CreateDirectory(i)
    End If
End Sub
Sub downloadupdate(ByVal location As String)
    My.Computer.Network.DownloadFile("http://dl.dropboxusercontent.com/s/e872b78tgcw3pbv/update.txt?dl=1&token_hash=AAFCqEhjemoPI2iKjvv3LbzfuwJ1Gd-G1Kb-Xcebef7tig", location)
End Sub
Sub checkupdate(ByVal location1 As String)
    If My.Computer.FileSystem.FileExists(location1) = True Then
        Dim update As String
        update = My.Computer.FileSystem.ReadAllText(location1)
        If update = My.Application.Info.Version.ToString Then
            MsgBox("No updates found!")
        Else
            MsgBox("Updates Found!")
        End If
    Else
        downloadupdate("C:\")
    End If
End Sub
End Class

以下是实际表格的代码:

Imports Updates.Class1
Public Class Form1
Public download As Updates.Class1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    download.bits()
    download.CheckFolder("C:\")
    download.downloadupdate("C:\")
    download.checkupdate("C:\")
End Sub
End Class

DLL文件作为参考导入到Forms应用程序 但它给了我这个错误 请帮忙吗?

1 个答案:

答案 0 :(得分:0)

您需要使用New关键字初始化类对象。

Public download As Updates.Class1

应该是:

Public download As New Updates.Class1