对象引用未设置为对象的实例(自动登录错误) [英] Object reference not set to an instance of an object ( Auto Login Error)
本文介绍了对象引用未设置为对象的实例(自动登录错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能帮我吗?我试图在自己的论坛中制作用于自动登录的小型软件,但出现此错误对象引用未设置为对象的实例".我认为问题在于我的论坛使用了不同的脚本,例如phpbb和smf,如果我可以登录这两个论坛之一,我会很高兴,因为我有超过15个论坛.这是代码,对于我的英语不好,我感到抱歉:
Can you help me? I trying to make a small software for autologin in my own forums but I get this error "Object reference not set to an instance of an object" . I think that the problem is that I have forums with diferent script like phpbb and smf , I will be happy if I can login in one of both because I have more than 15 forums.This is the code and sorry for my bad english:
Public Class Form1
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
ProgressBar1.Maximum = e.MaximumProgress
ProgressBar1.Value = e.CurrentProgress
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
If ProgressBar1.Value = ProgressBar1.Maximum Then
WebBrowser1.Document.GetElementById("user").SetAttribute("value", user.Text)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", password.Text)
WebBrowser1.Document.GetElementById("login_button").InvokeMember("click")
End If
End Sub
End Class
推荐答案
您没有告诉我们发生异常的位置.
我要猜测并说它在这里:
You didn''t tell us WHERE the exception is occurring.
I''m going to guess and say that it''s here:
WebBrowser1.Document.GetElementById("user").SetAttribute("value", user.Text)
改为这样:
Do it this way instead:
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("user")
If (element IsNot Nothing) Then
element.SetAttributes("value", user.Text)
End If
这篇关于对象引用未设置为对象的实例(自动登录错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文