r/visualbasic • • 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. 😁

7 Upvotes

11 comments sorted by

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"

2

u/BearScratch Nov 17 '20

Sounds good. Thanks

3

u/laancelot Nov 06 '20

Yes, they can. Have fun!

2

u/BearScratch Nov 17 '20

I really am. I'm kinda enjoying VB

1

u/laancelot Nov 17 '20

Love your mindset. PM me if you need any help.

1

u/WatsUpFuckers Nov 06 '20

yes! also, i would recommend picking up C# over VB

1

u/BearScratch Nov 17 '20

I'm taking C# next semester as an elective, but VB was a required class

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

u/[deleted] Nov 06 '20

[removed] — view removed comment

1

u/BearScratch Nov 17 '20

Gotcha. Thanks