vb.net - Problems when calling a public sub -


i'm facing deadend when trying call sub :

   public sub backblue(byval frm form, byval boxname string)       = 1 3           ctype(frm.controls(boxname & i.tostring()), textbox).backcolor = color.lightblue       next    end sub 

with button click event :

      private sub button1_click , bla bla....          backblue(me, "txb1_")       end sub 

can show me suggestion fix code.

it throws "object referrence not set instance bla bla" error

for information textbox names : txb1_1 , txb1_2 , txb1_3 (these of many textboxes in form want bakcolor changed)

and these 3 textboxes created through designer, not execution.

i did check textboxes names , there's nothing wrong.

the form class public.

try this....

public sub backblue(byval frm form, byval prefix string)    = 1 3         dim bxname string = prefix & i.tostring()         dim bx textbox = ctype(frm.controls(bxname), textbox)        if bx nothing           msgbox("unable find text box " +bxname)           dim mtch() control = frm.controls.find(bxname, true)           if mtch.length> 0               bx = mtch(0)           else               continue           end if         end if        bx.backcolor = color.lightblue    next end sub 

although, better solution either create textboxes inside control , pass control backblue or create collection has controls , pass in. brings yor problem your control contained in sub component , not in main form control collection

alternative, use either tag of control or create component control implements iextenderprovider , add form --all of above allow define controls and/how should handled @ designtime.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -