Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim i As Long
Dim s As String
Dim k As Object
If KeyCode = 13 Then '如果按下了回车键 i = Val(Text1.Text) '转数字,
'没写范围判断,因为通过循环后,不在范围内的数据无法找到控件也就是无结果 s = "Label" & i'注意大小写 For Each k In Form1.Controls '查找所有的控件 If k.Name = s Then '找到了指定名字的 k.Caption = i'给值 Exit For '退出循环 End If Next
End If
End Sub