·一周点击排行
·热点推荐
您的位置:首页 >> 计算机 » 等级考试 » 让VB在程序中显示错误行 >> 正文

让VB在程序中显示错误行

发布时间:2008-5-30 15:01:00 浏览次数: 380

以下代码行假设你在文本框中显示错误行,这些代码稍加更改就可以适用其他范围。

  首先,在窗体中建立一个“线”控件,并把它的索引号定为0。接着,添加如下的代码:

  Private Sub SetErrorState(ByVal ErrorState As Boolean, _
  ByRef Control As Control)
  On Error Resume Next
  Load linError(Control.Index)

  With linError(Control.Index)
  Set .Container = Control.Container
  .X1 = Control.Left
  .X2 = Control.Left + Control.Width
  .Y1 = Control.Top + Control.Height + 10
  .Y2 = Control.Top + Control.Height + 10
  .BorderColor = VBRed
  .Visible = ErrorState
  End With
  End Sub

  以上程序将会在一个控件数组中建立新的线以匹配引入的控件。然后,设置线的容器以处理标签控件中的文本框。它设置了线的位置和颜色,如果ErrorState为True,线为可见。

  在文本框的Validate事件添加以下代码,以调用SetErrorState方法:

  If Text1(Index).Text = "1" Then
  注释:==Valid
  Call SetErrorState(False, Text1(Index))
  Else
  注释:==Invalid
  Call SetErrorState(True, Text1(Index))
  End If

  相比于信息对话框,使用行来显示错误状态很少打断开发人员的编程思路,并且这一方法很容易学会。


讨论此主题请进>>: 让VB在程序中显示错误行