VB-If,Else,那......我想

时间:2015-01-06 00:10:18

标签: vb.net

嗨,我今天早上刚刚开始对vb完全陌生......我什么都不知道 我试图建立一个搜索引擎,但我有一些麻烦,这是我到目前为止

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text = "" Then
        MsgBox("Please make an input")
    End If

     TextBox1.Text = "message" Then
    MsgBox("Yaw searcher is now searching for your input")
    Timer1.Enabled = True
    MsgBox("File Found,redirecting to search results")
    System.Diagnostics.Process.Start("https://www.google.com/search?q=" + _
        TextBox1.Text + _
    "%3F&aqs=chrome..69i57j0j69i65l3j69i60.3515j0j7&sourceid=chrome&es_sm=93&ie=UTF-8")

我试图这样做,以便如果输入任何消息,程序就会出现并说出

    MsgBox("Yaw searcher is now searching for your input")
    Timer1.Enabled = True
    MsgBox("File Found,redirecting to search results")
    System.Diagnostics.Process.Start("https://www.google.com/search?q=" + _
        TextBox1.Text + _
    "%3F&aqs=chrome..69i57j0j69i65l3j69i60.3515j0j7&sourceid=chrome&es_sm=93&ie=UTF-8")

如果不是它说pelase做了一个输入...我得到那个部分但是不能得到最后一部分感谢帮助

2 个答案:

答案 0 :(得分:2)

您不需要额外的if检查@prospector uses in his answer,因为String.IsNullOrEmpty将涵盖两种情况(null或VB.NET案例{{1} }和Nothing):

String.Empty

请注意,Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'check if the textbox content is empty or null If String.IsNullOrEmpty(TextBox1.Text) Then MsgBox("You need to enter something to search for!") 'if not empty or null, search google for that keyword instead Else MsgBox("Yaw searcher is now searching for your input") MsgBox("File Found,redirecting to search results") System.Diagnostics.Process.Start("https://www.google.com/search?q=" + TextBox1.Text) End If End Sub 并非真正需要或提供信息,因为当您致电MsgBox("File Found,redirecting to search results")时,实际的Google搜索会在浏览器中启动。

这是最简单的形式,这是VB.NET中的Process.Start语法:

If-Then-Else

来自MSDN的"If...Then...Else Statement (Visual Basic)"(稍加修改)的示例:

If SomeCondition Then
    DoSomething()
ElseIf SomeOtherCondition Then
    DoSomethingElse()
Else
    DoSomethingIrrelevant()
End If 

答案 1 :(得分:0)

你应该使用If,Else,然后使用End If

This Link will help you understand

  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text = "" Then
        MsgBox("Please make an input")
    ElseIf TextBox1.Text = "message" Then
           MsgBox("Yaw searcher is now searching for your input")
           Timer1.Enabled = True
           MsgBox("File Found,redirecting to search results")
           System.Diagnostics.Process.Start("https://www.google.com/search?q=" + TextBox1.Text + "%3F&aqs=chrome..69i57j0j69i65l3j69i60.3515j0j7&sourceid=chrome&es_sm=93&ie=UTF-8")

    Else
        MsgBox("input is not message or blank")
    End If