2017-08-05 76 views
0

我試圖結束2如果語句在一行如何在一行上結束多個if語句

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

     If showing = True Then 
      Do 
       txtpassword.Text = "" 
       If txtpassword.Text = password Then 
        My_Private_Screen.Show() 
        Me.Hide() 
        showing = False 
        attempts = 0 
       ElseIf txtpassword.Text = "" Then 
        Do 
         If txtpassword.Text = password Then 
          My_Private_Screen.Show() 
          Me.Hide() 
         End If 
        Loop Until Inc = 5 
        Me.Hide() 
        showing = False 
        Do 

        Loop Until Inc2 = 300 
        Me.Show() 
        showing = True 
       Else 
        MessageBox.Show("Incorrect Password") 
        attempts = attempts + 1 
      Loop Until attempts = 5 
      Me.Hide() 
     End If 

     showing = False 

所以我需要知道如何結束2 ifs。我想知道怎麼做這樣的事情:

 Me.Hide() 
    End If 
    End If 

或者

Me.Hide() 
    End If End If 
+1

你不能那不是如何VS解析的語句,還上面的代碼不會編譯...當你這樣做,你將有一個堆棧溢出異常... – Codexer

+0

您可以在一個行結束多'If' :'結束如果:結束如果'。但是,即使你想要,你的代碼的邏輯也不會允許它,因爲你想結束在它之外開始的循環。 – djv

+0

哦,好吧,我只是認爲這可能是可能的。 –

回答

0

您需要如果循環之前結束內。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 

    If showing = True Then 
     Do 
      txtpassword.Text = "" 
      If txtpassword.Text = password Then 
       My_Private_Screen.Show() 
       Me.Hide() 
       showing = False 
       attempts = 0 
      ElseIf txtpassword.Text = "" Then 
       Do 
        If txtpassword.Text = password Then 
         My_Private_Screen.Show() 
         Me.Hide() 
        End If 
       Loop Until Inc = 5 
       Me.Hide() 
       showing = False 
       Do 

       Loop Until Inc2 = 300 
       Me.Show() 
       showing = True 
      Else 
       MessageBox.Show("Incorrect Password") 
       attempts = attempts + 1 
      Endif 
     Loop Until attempts = 5 
     Me.Hide() 
    End If 

    showing = False 
+0

ohhhhh thx尋求幫助。有效! –