【发布时间】:2015-12-15 20:17:30
【问题描述】:
这是一个 Windows 窗体应用程序的一部分,它会提示用户“请输入销售订单”,然后会打开一个 CAD 绘图。但是,我在“dsDoc = dsApp.GetActiveDocument()”处遇到错误。谁能帮我解决这个问题?谢谢!
Private Sub startButton_Click(sender As Object, e As EventArgs) Handles startButton.Click
Dim salesOrder As Integer
If Int32.TryParse(txtboxSalesOrder.Text, salesOrder) Then
If salesOrder > 99999 AndAlso salesOrder <= 999999 Then
Using process As Process = New Process
Dim ProcessProperties As New ProcessStartInfo
ProcessProperties.FileName = "C:\Program Files\Dassault Systemes\DraftSight\bin\DraftSight.exe"
ProcessProperties.Arguments = ("C:\Users\MyUserName\Desktop\JE5022AA.dwg")
ProcessProperties.WindowStyle = ProcessWindowStyle.Hidden
process.Start(ProcessProperties)
End Using
Dim dsApp As DraftSight.Application
Dim application As Object
dsApp = Nothing
application = Nothing
Dim dsDoc As DraftSight.Document
dsDoc = dsApp.GetActiveDocument()
'An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication2.exe
'Additional information: Object reference not set to an instance of an object.
If dsDoc Is Nothing Then
Return
End If
【问题讨论】:
-
好吧,在你有
dsApp = Nothing之前只有几行,接下来的 3-4 行中没有任何东西初始化它,所以当你尝试从中GetActiveDocument()时,dsApp直到 Nothing/null
标签: vb.net winforms visual-studio