Check for empty TextBox controls in VB.NET

2020-02-01 18:34发布

Ive got a Form application in VB.NET.

I have many text boxes on one form (about 20). Is there anyway to check them all at once to see if they are empty instead of writing out a massive line of code to check each one individually such as

If txt1.text = "" Or txt2.text="" Then
    msgbox("Please fill in all boxes")

That just seems like a long way around it?

7条回答
Rolldiameter
2楼-- · 2020-02-01 19:30

Sub for check Empty Textbox in GroupBox, you can use this:

Public Sub CheckEmptyTextbox(Byval groupbox as GroupBox)

Dim txt as control

For Each txt in groupbox.Controls

  IF TypeOF txt is Textbox then

     IF txt.Text="" Then


      MsgBox("Please Input data to textbox.")

      Exit For

     End IF

  End IF

Loop


End Sub
查看更多
登录 后发表回答