Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

vb.net - How disable a button if there is no text in multiple textboxes in VB?

I have 9 TextBoxes called Textbox1 all the way to Textbox9. I also have a button called Letter which selects a random letter from an array. I have another button called Start. This button when pressed displays a timer counting down from 30 seconds all the to zero. I want this button to take place only if all the 9 textboxes have text in them. I tried the following but it did not seem to work:

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change all of your "And" in your if statement to "Or"

Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
    If TxtBox1.Text = "" Or TxtBox2.Text = "" Or TxtBox3.Text = "" Or 
       TxtBox4.Text = "" Or TxtBox5.Text = "" Or TxtBox6.Text = "" Or
       TxtBox7.Text = "" Or TxtBox8.Text = "" Or TxtBox9.Text = "" Then
       TmrGame.Enabled = False
       MessageBox.Show("There Must Be A Total Of Nine Letters To Start The Game", "Not Enough Letters")
    Else
       TmrGame.Enabled = True
    End If
End Sub

By using And, you're checking that all of the text boxes must be blank, then you'll set your timer.Enabled to false. With Or, you're saying if any of the text boxes are blank you'll set the timer.Enabled to false.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...