[futurebasic] Re: [FB] SimpleCalculator

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: <rckrueger1@...>
Date: Mon, 14 Jan 2008 14:24:58 -0500
Thanks for the feedback.  I myself have been programming since '73.  Started with BASIC on a computer the size of a closet, then AppleSoft BASIC in '79, and then FutureBasic II since '94 or '95.  But you know, I could get away with the sloppy conventions then. Not the case now.  And I never had to mess with creating a project.

As far as the SimpleCalculator is concerned, num1, num2 & answerSum have already been changed to accomodate floating point numbers.  (Believe me, I was happy just to get plain integers to show up in the window.)

Thanks again for taking the time to send the feedback and suggestions.  I need whatever help I can get.  Don't hesitate to write.


---- maxclass@... wrote: 
> Bob,
> 
> Just a few tips that might make your programming life much easier  
> down the road. Everybody has their own style of coding but I have  
> found all of the below tips have served me well for over 21 years.
> 
> 
> On Jan 13, 2008, at 10:56 PM, bob krueger wrote:
> 
> > Brian, thanks for answering my post.
> >
> > Here is the program--needs to be tweaked yet, 'cuz I wanted to get  
> > the reply back ASAP  Controls 1& 2 are the addends, Control 3 is  
> > the sum, Control 4 is the button (Press to Calculate).
> 
> Just a couple of helpful hints [IMHO].
> 
> > Bob's code:
> > include "Tlbx IBCarbonRuntime.incl"
> > include "Tlbx HIView.incl"
> > include "Tlbx ControlDefinitions.incl"
> > include "NibToFB.incl"
> 
> The above is fine for a one file program.
> 
> If you are creating a Project place these references at the top of  
> the Project.
> 
> > Begin globals
> > 'name of nib file
> 
> Good rule of thumb here.
> 
> Any var's that you are defining as 'globals' by convention should  
> normally all start with the letter 'g'. You will see this throughout  
> most of the code posted on the site and it is a good practice to get  
> into.
> 
> Dimensioning of variables should always be specific, never left to  
> chance, such as:
> 
> dim as long gNum1   // or long or boolean, etc
> dim as single gNum1  // or double, etc.
> 
> This will keep you out of trouble with unexpected surprise results  
> later.
> 
> The variables dim'd below will probably default to integer and would  
> not allow real numbers to be used.
> As for strings, I think undimensioned strings default to 255 bytes.  
> Doing the following take the guess work out of it.
> 
> Better to use something like:
> 
> dim as str64 gNibFileNameStr
>      or
> dim as str32 number1Str   / or dim as str15 ... etc.
> 
> > dim gNibFileName$
> > gNibFileName$ = "calc.nib"
> >
> > dim num1, number1$
> > dim num2
> > dim answerSum
> 
> This is a good practice with using constants instead of hard coded  
> numbers.
> They are much more descriptive and make your code self documenting  
> and allow for global changes in the future.
> 
> > _calculateBTN = 4
> > _gQuit = 99
> >
> > local mode
> > local fn BuildUIFromNib
> > '~'1
> 
> These are perfect.
> 
> > dim as IBNibRef    @ nib
> > dim as WindowRef   @ w
> > dim as OSStatus      err
> 
> Hope this is of some help now and in the future.
> 
> Max Taylor
> The MaxClass Guy
> 
> 
> 
> 
> --
> To unsubscribe, send ANY message to: futurebasic-unsubscribe@...