Vb.net Vb错误对象引用未设置为对象的实例
我在为我的程序创建更新程序时遇到问题。当按下按钮时,它只会给我这个错误: 对象引用未设置为对象的实例 我有一个dll文件和一个表单应用程序文件 以下是dll文件的代码:Vb.net Vb错误对象引用未设置为对象的实例,vb.net,Vb.net,我在为我的程序创建更新程序时遇到问题。当按下按钮时,它只会给我这个错误: 对象引用未设置为对象的实例 我有一个dll文件和一个表单应用程序文件 以下是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)") = Fa
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文件作为表单应用程序的引用导入
但它给了我这个错误
请提供帮助?您需要使用
New
关键字初始化类对象
Public download As Updates.Class1
应该是:
Public download As New Updates.Class1
您能提供发生错误的堆栈跟踪或行号吗?现在它说“给定的文件路径以目录分隔符字符结尾”。对于根驱动器,我认为您不需要路径分隔符。