对于一个项目,我需要在运行时创建文本框,为此我使用了这段代码;
def send_test_email
Merchant.test_production_email
render json: nil, status: :ok
end
然后我可以使用这个For循环来循环它;
-------------------------------------
/var/log/aws-sqsd/default.log
-------------------------------------
2015-10-23T07:09:59Z message: sent to %[http://localhost:80/schedule/send_test_email]
2015-10-23T07:09:59Z http-err: 257fb276-d39e-4068-baf0-9106434674c5 (1) 502 - 0.004
2015-10-23T07:10:01Z message: sent to %[http://localhost:80/schedule/send_test_email]
2015-10-23T07:10:01Z http-err: 257fb276-d39e-4068-baf0-9106434674c5 (2) 502 - 0.007
2015-10-23T07:10:03Z message: sent to %[http://localhost:80/schedule/send_test_email]
2015-10-23T07:10:03Z http-err: 257fb276-d39e-4068-baf0-9106434674c5 (3) 502 - 0.004
2015-10-23T07:10:05Z message: sent to %[http://localhost:80/schedule/send_test_email]
但是,当代码到达该行时,这在理论上有效;
Dim AOP As Integer = GlobalVariables.AOP
Dim tb(11, 11) As TextBox
Dim LocationX As Integer
Dim LocationY As Integer
Dim count As Integer = 2
LocationX = 10
LocationY = 10
tb(1, 0).Name = "txtRoot"
tb(1, 0).Size = New Size(170, 20)
tb(1, 0).Location = New Point(LocationX, LocationY)
tb(1, 0).Visible = False
它返回错误'对象引用未设置为对象的实例' 我想知道是否还有这个?或者如果这种创建文本框的方式不可行?任何帮助将不胜感激。
答案 0 :(得分:2)
您已初始化数组但未添加已初始化的TextBoxes
,该数组目前仅包含Nothing
。另请注意,数组基于零,因此第一个TextBox
位于tb(0, 0)
。
For i As Int32 = 0 To tb.GetLength(0) - 1
For ii As Int32 = 0 To tb.GetLength(1) - 1
tb(i, ii) = New TextBox()
tb(i, ii).Visible = False
' .... '
Next
Next
现在全部都已初始化。