VB.NET: Create and Apply Basic Classes
Does anyone know how to create classes and apply it without occur any error correctly...
I find that most of my coding is inside the forms and i am not using any classes at the monent...
thus i find it quite hard if i need to change the coding......i would search all the forms just for the word that i need to change..
Therefore i am eager to change my style of coding and uses classes more instead..
This is quite basic..
Can anyone sent me some useful links, advise or tutorials about that..
Thanks
1 Attachment(s)
Re: VB.NET: Create and Apply Basic Classes
Recently, i borrow a book from the author of Bradley/Millspaugh...
I try the code on one of the chapters where it uses the class..
I come across one HandOn program where i can't understand why the class of Payroll is not declared in the frmSummary form and it can still be use...
but in the frmPayRoll form, it must declared a new instance of object first before it can be use...
Can someone spare some time and look into this two forms...
I can't figure out the reason...
Thanks
Re: VB.NET: Create and Apply Basic Classes
lblCount.Text = Payroll.NumberProcessed.ToString()
lblOvertime.Text = Payroll.OvertimeHours.ToString()
lblTotalPay.Text = FormatCurrency(Payroll.TotalPay)
Are you talking about this one? It's because those properties are Shared. A member of the class, not the object itself. Notice the Console.WriteLine()? WriteLine() is a shared member method of Console class. You need no intantiation. Instantiation is for object and we are dealing about the class member.
Re: VB.NET: Create and Apply Basic Classes
Hi
The class can be used by frmSummary without creating an instance of the class because the following properties are all declared Shared.
VB Code:
Shared ReadOnly Property NumberProcessed() As Decimal
Shared ReadOnly Property TotalPay() As Decimal
Shared ReadOnly Property OvertimeHours() As Decimal
Acording to MSDN The Shared keyword indicates that one or more declared programming elements are shared. Shared elements are not associated with a specific instance of a class or structure. You can access them by qualifying them either with the class or structure name, or with the variable name of a specific instance of the class or structure.
Regards
Jorge