jwcolby
jwcolby at colbyconsulting.com
Sat Oct 10 08:35:01 CDT 2009
Shamil, I have to say I wonder why the sudden distaste for Hungarian. I can see dropping the class thing since everything is now a class but the point of prefixing with the data type (str, int, dbl, dec etc) is to tell the programmer at a glance the data type so that they don't need to do anything to discover that. Why is it such a crime now to want to be able to read that instantly? Does it not work as well as it ever did? I find it amusing that the author recommends spelling everything out in full (no abbreviations) adding entire words to the end to denote specific types of constructs, dozens of new things to learn as a convention, yet Hungarian for the variables is verboten. And to top it all off, all this is "industry accepted standard naming conventions" EXCEPT for the fact that "they (Microsoft) aren't even consistent in their internal code in the .NET framework". Hmmmm........ John W. Colby www.ColbyConsulting.com Shamil Salakhetdinov wrote: > Hi John, > > You can put your initialization code into your form constructor or Form_Load > event processing method. > > BTW, I see you still use Hungarian notation/LRNC - try to forget it ASAP > when programming on C# - and you'll feel a great relieve. > Guaranteed/tested/proven by many developers. There are .NET natural naming > conventions recommended by MS. Try to find and use them. Here is one source: > > http://www.irritatedvowel.com/Programming/Standards.aspx > > Here is a VS plug-in to help you get accustomed to the new naming > conventions: > > http://www.codeplex.com/StyleCopForReSharper > > Although I haven't used it yet. > > --Shamil > > > > -----Original Message----- > From: dba-vb-bounces at databaseadvisors.com > [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby > Sent: Friday, October 09, 2009 8:25 PM > To: VBA > Subject: [dba-VB] Error when passing controls to the constructor of a class > > I am very much a novice at C#. For my homework project I am trying to use > classes (next semester > stuff) and I have some processing that needs to manipulate controls back on > the form. I have three > instances of a Grades (plural) class which has to display the current grade, > but only when a grade > is added, deleted or modified in that specific instance. > > Additionally I have a set of controls on the form that are filled with data > about all of the grades > so the next level class (supervisor to clsGrades) has to update those > controls. > > So I'm thinking I would create a clsGradesDisplay, instantiate two of this > class up in the form, and > pass in the four text boxes that have to be manipulated. Then I can pass > that class off to the > child classes so that they can manipulate the text boxes as they need to. > This makes sense because > those child classes actually contain the data that has to be displayed. ATM > I simply pass the data > back up the chain and have the form do the update, but it would be cleaner > and less confusing to > have the class that contains the data do the updates directly. > > My problem is that I get a compile error when I try to pass in the text > boxes to the constructor of > this clsGradesDisplay. > > The class constructor looks like this: > > class clsGradeDisplay > { > public TextBox txtGradeCnt; > public TextBox txtGradeSum; > public TextBox txtGradeAvg; > public TextBox txtGradeWeightedAvg; > /*Constructor - initializes the pointers to the text boxes > */ > public clsGradeDisplay(TextBox ltxtGradeCnt, TextBox ltxtGradeSum, > TextBox ltxtGradeAvg, > TextBox ltxtGradeWeightedAvg) > { > txtGradeCnt = ltxtGradeCnt; > txtGradeSum = ltxtGradeSum; > txtGradeAvg = ltxtGradeAvg; > txtGradeWeightedAvg = ltxtGradeWeightedAvg; > } > } > > > Back in the header of the form I am tring to initialize the instances as > follows: > > clsGradeDisplay mGDCurrent = new clsGradeDisplay( txtCntOfGrades, > txtSumOfGrades, txtAvgGrade, > txtWeightedScore); > > > The error is: > > Error 4 A field initializer cannot reference the non-static field, > method, or property > 'Grade_Calculator.frmGradeCalculator.txtWeightedScore' > > It seems like it should work. I am allowed to initialize a class passing in > values correct? Is > there some special syntax for passing pointers to controls? > > What am I doing wrong? > > > TIA, >