這是我先生混亂再次。編譯後需要幫助嘗試從.txt文件調用
我試圖在運行時從我的計算機上的.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
酷感謝一步一步的指導。馬特。 – user1096419 2012-07-16 15:22:17