r/visualbasic • u/BearScratch • Nov 06 '20
Visual Studio 2019 multiple form question
I have a general question. I'm taking visual basic in school and the program I'm working on has multiple forms.
My only question is can the controls have the same name on each form?
Like, in one form have a control called "lblTotalCost" and one on the other form with the same name and not mess anything up.
Please help this noob. 😁
3
u/laancelot Nov 06 '20
Yes, they can. Have fun!
2
1
1
u/revennest Nov 06 '20
Very old way to naming object, I believe your class still use old book as reference to teaching; you can name it as "total_cost" or "total_cost_label", it's much more readable and less chance to typo.
About name conflict, long as it isn't in same scope you can use it all you want because it full name will be "my_project.form_1.total_cost" and "my_project.form_2.total_cost", so it isn't the same name as you think it is.
1
u/BearScratch Nov 17 '20
Thanks. I name it that way cause its easy for me to pick things out, not cause I was taught to. I do the same in Microsoft access with qry for query and tbl for table
2
5
u/RJohn12 Nov 06 '20
Yep, they can have identical names.
then, If you wanted to use those controls you could call the by including the form name like this:
form1.txtBox1.text = "bla a bla"
form2.txtBox1.text = "different text"