1

谢谢阅读。我正在编写一个程序来创建一个由 8 个列组成的列表。所以有8个列表框和每个下面的文本框。如果有人为空,我想一一检查每个文本框。...而且不知道该怎么做!

我需要你的帮助!谢谢

4

1 回答 1

1

而不是使用 8 个列表框,您可能会考虑使用 flexgrid 控件

但是使用 8 个列表框和 8 个文本框,您可以将它们创建为数组并按如下方式检查它们:

'1 form with with
'    1 listbox : name=List1   index=0
'    1 textbox : name=Text1   index=0
'    1 commandbutton : name=Command1

Option Explicit

Private Sub Command1_Click()
  If IsEmpty Then
    MsgBox "Textboxes are all empty", vbInformation, "IsEmpty"
  Else
    MsgBox "At least 1 Textbox is not empty", vbInformation, "IsEmpty"
  End If
End Sub

Private Sub Form_Load()
  Dim intIndex As Integer
  For intIndex = 1 To 7
    Load List1(intIndex)
    Load Text1(intIndex)
    List1(intIndex).Visible = True
    Text1(intIndex).Visible = True
  Next intIndex
  Move 0, 0, 10000, 10000
End Sub

Private Function IsEmpty() As Boolean
  Dim intIndex As Integer
  Dim blnEmpty As Boolean
  blnEmpty = True
  For intIndex = 0 To Text1.Count - 1
    If Len(Text1(intIndex).Text) > 0 Then
      blnEmpty = False
      Exit For
    End If
  Next intIndex
  IsEmpty = blnEmpty
End Function

Private Sub Form_Resize()
  Dim intIndex As Integer
  Dim sngWidth As Single
  Dim sngListWidth As Single, sngListHeight As Single
  Dim sngTextHeight As Single
  Dim sngCmdHeight As Single
  sngWidth = ScaleWidth
  sngListWidth = sngWidth / List1.Count
  sngTextHeight = 315
  sngCmdHeight = 315
  sngListHeight = ScaleHeight - sngTextHeight - sngCmdHeight
  For intIndex = 0 To List1.Count - 1
    List1(intIndex).Move intIndex * sngListWidth, 0, sngListWidth, sngListHeight
    Text1(intIndex).Move intIndex * sngListWidth, sngListHeight, sngListWidth, sngTextHeight
  Next intIndex
  Command1.Move 0, sngListHeight + sngTextHeight, sngWidth, sngCmdHeight
End Sub
于 2012-11-14T06:41:16.537 回答