2015-01-06 1 views
0

Ну привет, я абсолютно новый для vb, который я только начал этим утром ... Я ничего не знаю Im пытается создать поисковую систему, но у меня есть проблемы, вот что я до сих порVB-If, Else, Then ... Я думаю,

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") 

Im пытается сделать так, что если вводится какое-либо сообщение, что программа будет подойти и сказать

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 сделать Imput ... Айв получил эта часть, но не могу получить последнюю часть спасибо за помощь

ответ

2

Вам не нужны дополнительные if проверки @prospector uses in his answer, как String.IsNullOrEmpty будет охватывать оба сценария (null, или в VB.NET-х случай 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 начинается в браузере, когда вы вызываете Process.Start.

В этом простейшей форме, вот If-Then-Else синтаксис в VB.NET:

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

пример из MSDN-х "If...Then...Else Statement (Visual Basic)" (слегка измененный):

Dim count As Integer = 0 
Dim message As String 

If count = 0 Then 
    'this will only run if count = 0 
    message = "There are no items." 
ElseIf count = 1 Then 
    'this will only run if count = 1 
    message = "There is 1 item." 
ElseIf count = 2 Then 
    'this will only run if count = 2 
    message = "There are 2 items." 
Else 
    'this will only run if count has any value other than 0, 1 or 2 
    message = "There are more than 2 items or less than 0 items." 
End If 
+1

Спасибо для вашей помощи. Я использовал ваш метод, так как я понял его больше ... также спасибо, что показал мне код IsNullOrEmpty, который я не знал, что этот код даже существует. Еще раз спасибо, и я надеюсь, что вы сможете мне помочь в будущем, как я сказал, прежде чем начинающий начал только 8 часов назад. Ty: p Bye –

0

Вы должны использовать Если, 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 
+0

Эй большое спасибо за ваш answeri будет пытаться furthere мои исследования с if, else и end, если команды с im im total noob ... lol спасибо tho, я только не использовал эту причину, я не понял это действительно спасибо за помощь, надеюсь, у вас будет возможность продолжать помогать мне –

Смежные вопросы