mysql - VB.NET 2013: Change label text -
i've been teaching myself vb.net couple of weeks now, , i'm stumped. have 18+ years experience in php, , far logic has been similar. can't figure out how dynamically specify label change text. have 50 labels, 1 each state. have mysql query pulling count state , updating label state.
my code is:
while datareader.read if datareader.item("state") = "co" lblco.text = "(" & datareader.item("total") & ")" lblco.visible = true end if end while what don't want make 50 "if" statements specify new text each label. each of labels start lbl , end 2 state abbreviation. example: lblca, lblco, lblfl.
i thought concatenate this: (similar style of concatenating in php)
while datareader.read lbl&datareader.item("state").text = "(" & datareader.item("total") & ")" lbl&datareader.item("state").visible = true end while i found out can't concatenate in vb.net.
does know how dynamically? or stuck making 50 "if" statements?
thank you!
i first want thank plutonix , mike_obrien. able combine both of responses make solution worked perfect me.
plutonix: figured out had ".text" in wrong place, overall snippet worked. oh, in vb.net 2013, forced me use "me." instead of form name.
mike_obrien: liked "isnot nothing" check
the solution worked perfect me:
while datareader.read if me.controls("lbl" & datareader.item("state")) isnot nothing me.controls("lbl" & datareader.item("state")).text = "(" & datareader.item("total") & ")" me.controls("lbl" & datareader.item("state")).visible = true end if end while so above make sure label exists. if exist, update text count pulled mysql. said before, i'm new vb.net. though code above works, if knows reason figured out might bad application or system, i'm open suggestions.
Comments
Post a Comment