vb.net函数不会在所有代码路径上返回值

时间:2013-02-27 22:39:04

标签: vb.net browser

我在VB.Net中创建了一个简单的函数get获取你输入文本框的字符串,并通过webbrower将其发送到文本框id“wgo”,然后点击提交..它给我警告“Function GetMessage( )不会在所有代码路径上返回值“。如果有人知道如何修复警告,或者如何以不同的格式捕获textbox1.text消息;请告诉我。

这是我正在使用的部分代码:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim elements = WebBrowser1.Document.GetElementsByTagName("input")   '' or whatever tag it is
    For Each element As HtmlElement In elements
        GetMessage() 'Get message from textbox1 and send it 
        If element.GetAttribute("className") = "submitbut" Then
            element.InvokeMember("click")
            MsgBox("Your ECHO has been broadcast!")
            Exit For
        End If
    Next
    TextBox2.Text = TextBox1.Text 'Displays what the sent message was
    TextBox1.Text = ""            'Erases old message from textbox1
    TextBox3.Text = getCurrentDateTimeString()  'Displays the time and date it was sent
End Sub

Function GetMessage()
    WebBrowser1.Document.GetElementById("wgo").SetAttribute("value", TextBox1.Text)
End Function

任何帮助将不胜感激!我是VB.net的新手,所以放轻松吧!再次感谢!

1 个答案:

答案 0 :(得分:0)

您的功能根本不会返回任何内容!

这是您希望的行为,您应该将其更改为Sub

Sub GetMessage()
    WebBrowser1.Document.GetElementById("wgo").SetAttribute("value", TextBox1.Text)
End Sub