需要帮助尝试在编译后从.txt文件调用

时间:2012-07-15 20:25:16

标签: vb.net browser

这是我再次混淆先生。

我试图在运行时间之后从我的计算机上的.txt文件添加此代码(调用此代码)。

在编译之前,我可以将此代码添加到我的表单中,并通过手动放置webbrowser.navigate&按钮下的addhandlers和其余部分,但我希望在我的应用程序通过单击按钮编译后添加此代码。

我对此的思考过程就是让代码在.txt中完成,然后在编译之前进入我的表单上的btn1并编码它说什么.txt我打开使用openfiledialog将代码拉入到形成并使用它。

我知道手动只需手动将webbrowser.navigate和addhandlers放在按钮下(并添加hanlders和表单的公共新实例)就可以了,但必须有更好的方法来实现这个目标我将要从中抽取大约500个.txt文件。

我在考虑循环浏览文件夹并抓住文件夹中的每个.txt并通过执行操作将它们调用到表单中?但是我在这一步失去了。

关于如何解决这个问题的任何想法?

由于

以下是其中一个.txt文件的代码。

'Connotea DECLARATION
Public Connotea as new captchawindow

Public Sub ConnoteaNavigate
Connotea.webbrowser1.navigate("http://www.connotea.org/register")
End Sub

Public Sub ConnoteaHandlers

AddHandler Connotea.button1.click, addressof Connoteabutton
AddHandler Connotea.webbrowser1.documentcompleted, addressof Connoteabrowsercompleted
End Sub

Public Sub Connoteabrowsercompleted

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "firstname" then
element.setAttribute("value", ProfileMaker.FirstName.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "lastname" then
element.setAttribute("value", ProfileMaker.LastName.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "username" then
element.setAttribute("value", ProfileMaker.Username.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "password" then
element.setAttribute("value", ProfileMaker.Password.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "passwordconfirm" then
element.setAttribute("value", ProfileMaker.Password.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "email" then
element.setAttribute("value", ProfileMaker.Email.Text)
End If
Next

For Each element as HtmlElement in Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "email2" then
element.setAttribute("value", ProfileMaker.Email.Text)
End If
Next

If Connotea.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
For Each Captcha As HtmlElement In Connotea.WebBrowser1.Document.Images
If Captcha.GetAttribute("src").Contains("http://www.google.com/recaptcha/api/image?c=") Then
Connotea.PictureBox1.Load(Captcha.GetAttribute("src"))
End If
Next
End If


End Sub

Public Sub Connoteabutton

Connotea.show

For Each element as HtmlElement in     Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("id") = "recaptcha_response_field" then
element.setAttribute("value", Connotea.Textbox1.Text)
End If
Next

For Each element as HtmlElement in             Connotea.WebBrowser1.Document.Getelementsbytagname("input")
If element.getattribute("value") ="register" then
 element.InvokeMember("click")
End If
Next

Connotea.dispose
End Sub

1 个答案:

答案 0 :(得分:0)

我认为您正在使用CodeDOM

寻找解决方案

This question on SO在C#中,但应该给你一些指示。

This article on the microsoft site提供了在VB中实现此目标的分步指南