[dba-VB] Error when passing controls to the constructor of a class

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Sat Oct 10 11:18:53 CDT 2009


Hi John --

Yes, it works well for me - programming without Hungarian notation in .NET
development - they say Hungarian is not needed because you can always use
Intellisense to see the type of variables etc.

I still use Hungarian notation sometimes in control names, and always when
naming MS SQL views, SPs, UDFs, triggers...

As for inconsistency in MS internal code - I suppose they can't quit
Hungarian notation habits overnight - but they are moving in the new
direction for sure...

--
Shamil

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Saturday, October 10, 2009 5:35 PM
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] Error when passing controls to the constructor of a
class

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,
> 
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4495 (20091010) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru






More information about the dba-VB mailing list