Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Enter percentages as whole numbers?
Message
From
26/01/2007 10:22:28
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
26/01/2007 09:55:50
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01189535
Message ID:
01189626
Views:
15
>>>>>>>I have a data entry form containing percentage fields that are defined as N(4,2). I would like the users to be able to enter 100% as 100 rather than 1.00, 50% as 50 rather than 0.50, and so on. Is there some formatting option that supports this or is my only option to change the field definitions to N(3,0)? (They can never be greater than 100%).
>>>>>>
>>>>>>Mike,
>>>>>>
>>>>>>Check Enhanced Numeric Textbox Class File #9395
>>>>>
>>>>>Is it really needed to use new classes for so simple thing?
>>>>
>>>>It isn't needed, but I've recently been working with some code I inherited.
>>>>
>>>>I've come across at least 15 occurances of...
>>>>
>>>>local m.schName, I
>>>>m.schName = ""
>>>>for i = 1 to len(m.tcAcctNum)
>>>> if substr(m.tcAccNum,m.i) = " "
>>>> m.schName = m.schName + "?"
>>>> else
>>>> m.schName = m.schName + substr(m.tcAccNum,m.i)
>>>> endif
>>>>endfor i
>>>>
>>>>Now. Tell me exactly how long it takes you to decipher that and exactly what it does, and even better, how you would have done it differently please.
>>>
>>>It seems to be a ChrTran problem.
>>>cSchname=chrtran(cAccnum,space(1),'?')
>>>Anything else I don't quite understand, i.e. how it's related to this thread?

Is it really necessary to use chrtran for so simple a thing? Absolutely!

>>
>>Chrtran is a "component" of vfp. One might say it's almost a class. You were willing to reuse something to solve the problem. Why not reuse a numeric textbox instead of trying to remember what format/code, etc. to apply to the problem?
>
>I don't think we have much to discuss here. Every rememberance is a complication for our poor brains, but every additional class is a complication too. One may create a class to produce 2x2=4, or any other similar operation, but then it's up to world to decide.

That example does not constitute a good class. Reduce a function to it's most reasonable granularity and then reuse it. You'd create a multiplier component at the very least or reuse the native ability of VFP to do the multiplication.

You most certainly would never:
x=2
y=2
lnmin = min(x,y)
lnmax = max(x,y)
lnanswer = 0
for i = 1 to lnmax
  lnanswer = lnanswer + lnmin
endfor
It is easy to separate the percentage formatting out of the textbox into a category of classes that handle such specialized formatting. Then you can tell the textbox to apply that formatting as well as others.

The lack of desire to reuse leads to having 15 copies of the same code which is a maintenance nightmare when the business rules change. This was done by a person that is a college teacher. The example is a business rule. It should have been a method of the class in question, and that method should have used chrtran. That method would then have been a single place to change the business rule, not only that, but looking at the code in the future one would see:

m.schname = this.FixStrings(m.acctnum)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform