vb.net:无法使用函数

时间:2017-04-02 14:45:45

标签: vb.net function

所以基本上这是一个浏览器代码,当我试图在喜欢的按钮中保存喜爱网站的链接时,我遇到了问题。问题是当我点击按钮btnFav1或btnFav2时,输入名称,键入它我想要存储的网址它看起来很完美。但是当我第二次点击它时它不会带我到网站,而是(关于:空白)出现在网址栏中。

Public Class Form1
Dim UrlF1,UrlF2,UrlF3,UrlF4,UrlF5 As string
Function FavUrl
    Dim Url As string = Inputbox("Enter Url")
    Return Url   
End Function
sub fav(a As object,b As object,c As string)

    If a.text = "" then
        a.Text = FavName 
        c = FavUrl
        b.Visible = true
    Else
        txtURL.text = c
        btnGo.PerformClick
    End If

End sub
Function FavName
    Dim Name As String = InputBox("What do you wanna call it?")
    Return Name   
End Function
Sub NavBar
    txtURL.Text = UrlReturn
End sub
Function UrlReturn
    Return WB.Document.Url.AbsoluteUri 
End Function
Private Sub btnFavs_Click(sender As Object, e As EventArgs) Handles btnFavs1.Click
    fav(btnfavs1,btnfavs2,UrlF1)
End Sub
Private Sub btnFavs2_Click(sender As Object, e As EventArgs) Handles btnFavs2.Click
    fav(btnfavs2,btnfavs3,UrlF2)

End Sub

1 个答案:

答案 0 :(得分:0)

这将是实现目标的另一种方式,而不用大惊小怪:

  Private Sub ButtonClickHandler(sender As Object, e As EventArgs) Handles btnFavs1.Click, btnFavs2.Click, btnFavs3.Click

        Try
            Dim thisBtn As Button = DirectCast(sender, Button)

            If thisBtn.Text.Length = 0 Then
                thisBtn.Text = InputBox("What do you want to call it?")
                thisBtn.Tag = InputBox("The URL") 'WB.Document.Url.AbsoluteUri
            Else
                txtURL.Text = thisBtn.Tag.ToString
                btnGo.PerformClick()
            End If

        Catch ex As Exception
            MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
        End Try

    End Sub