i am trying to create a dll containing a webbrowser control. What i want it to do is this: i have a form which calls a function from that dll. the dll naigates to a webpage, say "www.google.com". after it navigates, it reads a string from the page body and executes some actions with it. The problem is, when the form calls the function inside the dll, the webpage is not loaded inside the dll, so there is no string to read. If i run the code of the dll as a windows application, the form loads, it navigates to the web site and reads the string... how should i modify the code inside the dll so when a form calls the funtion inside it, it first loads the webpage, and after that execute the called function? a sample of the code is here, this is the code which i compile as a dll:
Imports SpeechLib
'Imports System.Speech
'Imports System.Speech.Recognition
Public Class Form1
Public WithEvents vox As New SpVoice
Dim myText As String
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
If TextBox1.Text <> "" Then
Dim htmlElements As HtmlElementCollection = WebBrowser1.document.GetElementsByTagName("input")
For Each el As HtmlElement In htmlElements
If el.GetAttribute("name").Equals("input") Then
el.SetAttribute("value", TextBox1.Text)
End If
Next
For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
If element.GetAttribute("type") = "submit" Then
element.InvokeMember("click")
End If
Next
Timer1.Enabled = True
TextBox1.Text = ""
TextBox1.Focus()
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Focus()
End Sub
Private Sub ReadWebString(byval StringToRead as String)
Dim htmlElements As HtmlElementCollection = WebBrowser1.document.GetElementsByTagName("input")
For Each el As HtmlElement In htmlElements
If el.GetAttribute("name").Equals("input") Then
el.SetAttribute("value", StringToRead)
End If
Next
For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
If element.GetAttribute("type") = "submit" Then
element.InvokeMember("click")
End If
Next
Timer1.Enabled = True
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
myText = Me.WebBrowser1.document.Body.InnerText.Substring(Me.WebBrowser1.document.Body.InnerText.IndexOf("Santa"))
If myText.StartsWith("Santa") Then
Dim StartS As String
Dim Ends As String
StartS = myText.Remove(0, myText.IndexOf(":") + 2)
Ends = StartS .Remove(StartS .LastIndexOf("You"))
vox.Speak(Ends)
Else
Console.WriteLine(myText)
End If
End Sub
End Class
and i want to call it from another form, like this:
ReadWebString("hello world!")

New Topic/Question
Reply




MultiQuote



|