本文介绍了Visual Basic:未将对象引用设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我观看了一个视频教程,看到这个人编写并执行下面的代码并工作,但是当我尝试编译我的代码时,它说对象引用未设置为对象的实例".我已经尝试了几件事,看看我是否能找到问题所在,但无济于事.
i watched a video tutorial and saw the guy write and execute the code below and worked but when i try to compile mine it says "object reference not set to an instance of an object". i have tried several things to see if i can get what the problem is but to no avail.
Imports System.IO
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim myline = New StreamReader("TextFile1.txt")
Dim line As String = ""
While Not IsNothing(line)
line = myline.ReadLine
If IsNothing(line) Then
TextBox2.AppendText(line)
End If
End While
myline.Close()
Catch ex As Exception
TextBox2.AppendText(ex.Message)
MsgBox(ex.Message)
End Try
End Sub
End Class
有人可以帮忙吗?谢谢
推荐答案
我认为您缺少一个不是:
If Not IsNothing(line) Then
TextBox2.AppendText(line)
End If
这篇关于Visual Basic:未将对象引用设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!