【发布时间】:2018-07-16 08:57:02
【问题描述】:
显然我在循环的第二个 if 条件中弄错了,我留下一张图片以便更好地理解。
由于某种原因,即使它们几乎相同,错误也不会在第一个 if 条件中显示。
为了把它放在上下文中,我有一个大的第一个文本框和其他 9 个小文本框。基本上我想把我写在大文本框中的值一个一个地发送给小的。
大文本框名称属性是 t0 而其他从 t1 到 t9
视觉基本代码
Public Class Form1
Dim array() As TextBox = {t1, t2, t3, t4, t5, t6, t7, t8, t9}
Private Sub t0_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles t0.KeyDown
If e.KeyCode = Keys.Enter Then
If sender.Text.ToString <> String.Empty Then
For indice As Integer = 0 To array.Length - 1
If array(indice).Text = String.Empty Then '<== The error is in this line
array(indice).Text = sender.Text.ToString
Exit For
End If
Next
End If
End If
End Sub
End Class
更新
Used等于这次,但仍然是同样的错误
【问题讨论】:
-
所以,您的数组似乎没有此索引或值为 null ;)
-
你是对的,声明文本框数组的正确方法是什么,显然我的有问题。请注意,我将文本框元素名称更改为 t0 到 t9
标签: vb.net