vb.net - VB For loop karstieji(x).Location = New Point(0, a) nullreferenceException was unhandled -


vb application freezes nullreferenceexception unhandled on new point(0 ,a) here code.

    x = 1 5         dim karstieji(x) label         dim karstieji1(x) button         dim integer         dim b integer         = 0         b = 0         panel2.controls.add(karstieji(x))         karstieji(x).location = new point(0, a)         karstieji(x).size = new size(140, 20)         karstieji(x).text = "bulvyniai blynai"         karstieji(x).font = new font(1, 12)         panel2.controls.add(karstieji1(x))         karstieji1(x).location = new point(140, b)         karstieji1(x).size = new size(12, 12)         += 20         b += 12     next 

you cannot use control arrays in vb.net code trying use not work.

i suggest using generic list if need keep reference controls:

'in class private _labels new list(of label) private _buttons new list(of button)   'create controls dim integer = 0 dim b integer = 0      x = 1 5         dim karstieji new label         dim karstieji1 new button         panel2.controls.add(karstieji)         karstieji.location = new point(0, a)         karstieji.size = new size(140, 20)         karstieji.text = "bulvyniai blynai"         karstieji.font = new font(1, 12)         panel2.controls.add(karstieji1)         karstieji1.location = new point(140, b)         karstieji1.size = new size(12, 12)         += 20         b += 12         'add reference controls can refer them later         _labels.add(karstieji)         _buttons.add(karstieji1)     next 

note have moved a , b variables outside loop these 0 otherwise


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -