Nice neat code posts


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    Hi Lester,
    No, I'm not particularly interested in the colours and I'm not asking you to enable/allow .html if that's a problem. My point was that many of the posts were they have already been used are no longer readable, like the ones in the thread I linked to. But if they wasn't supposed to be there in the first place then you've made your point.

    Again, I know how to format the code using BB-code but that's just it - simply cut'n'paste well formated code from an editor/IDE to a post usually needs quite a bit of touch-up afterwards. Again, disregard the colours, I'm talking about tabs, blank lines etc. Just what Charles mentioned in his original post. I'm not saying it's yours or the forums fault. I'm, like Charles, asking what's needed to preserve the formatting when copying code into a post.

    /Henrik.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    Below is an unedited cut-and-paste from MCS. Even when I go back and try to clean it up, the final results look terrible. I'd post more code if it didn't look so bad.



    Code:
    GetNum:
            Result = 
    0
            MaxNum = 
    5     ; set for max number of digits you will 
    accept
            YY = 
    1
     
    POSN=0
            IsNeg = 
    0
            TimedOut = 
    0
            ArrayWrite InputString,[Rep 
    $FF\8]  ; Fill with 
    $FF
     
    GetMoreN:              
     
            HSERIN 
    9000,InputTimeout,[Keyin]
     
    IF Keyin = ESC THEN 
    ZeroNum
                If 
    Keyin = CR THEN 
    DunInputn
     
    If allowNeg 
    then
                IF 
    Keyin = "-" and Posn = 0 THEN 
     
     
    IsNeg = 
    1
     
    Hserout 
    ["-"]
     
    goto 
    GetMoreN
     
    ENDIF 
     
    endif   
     
                IF Keyin 
    = BS 
    THEN
     
    HSEROUT 
    [BS,SP,BS]
     
    IF POSN > 0 
    THEN
     
    POSN = POSN - 
    1
     
    InputString [POSN] = 
    $FF
     
    GOTO 
    GetMoreN
     
    ENDIF   
     
     
    ENDIF
            IF Keyin < "0" or Keyin 
    > "9" THEN GetMoreN 
            HSEROUT 
    [Keyin]
            InputString [POSN] = Keyin 
    - "0"
            IF POSN >= (MaxNum -1) 
    THEN DunInputN
            POSN = POSN 
    +1
            GOTO 
    GetMoreN
    DunInputN:
            For xN = 7 
    to 0 STEP - 1 
     
    IF InputString[XN]= 255 THEN 
    NoMoreNum
     
    Result = Result + 
    (InputString[xN]*YY)
     
    YY = YY 
    *10
    NoMoreNum:            
     
            Next 
    XN
     
     
            If Isneg 
    then
              If result < 
    32768 
    then
     
    Result = 0 - Result
     
    else
    Charles Linquist

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    Charles,

    Attach your code (BAS/PBP) so I can try it if you do not mind.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    I have to agree with others here ...not only posting code snippets can be plain ugly....also reading others' old snippets with with the wrong (now incompatible) formatting renders them virtually unreadable.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    Just testing...

    Copy/Paste from Programmers Notepad
    Code:
    ' 12F675 
    ' 09/05/2011  
    DEFINE OSC 4
    ' SET FOR INTERNAL OSC AND MCLRE OFF
    #CONFIG
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    ANSEL=%00000000         ' ADC SET FOR DIGITAL 
    CMCON=7                 ' COMPARATOR SET FOR DIGITAL
    SWITCH_OFF  VAR GPIO.1  ' PUSH BUTTON FOR PUMP OFF
    SWITCH_RUN	VAR	GPIO.2  ' PUSH BUTTON FOR PUMP ON  
    LED_RUN     VAR GPIO.0  ' INDICATE RUN SIGNAL SENT  
    LED_OFF     VAR GPIO.5  ' INDICAT STOP SIGNAL SENT
    TX          VAR GPIO.4  ' DATA SEND PIN
    BAUD        CON 18030	' 18030 = 600 BAUD
    
    START:     ' SEND OFF SIGNAL AT POWER UP
        PAUSE  1000
        HIGH LED_OFF  
        SEROUT2 TX, BAUD,["OFF",13]  
    DO  ' LOOP TO CHECK PUSH BUTTONS
    	DO WHILE SWITCH_RUN = 1     ' CHECK ON PUSH BUTTON
    	   ' IF BUTTON PUSHED
    		HIGH LED_RUN          ' RUN INDICATOR ON
    		LOW LED_OFF           ' OFF INDICATOR OFF
    		PAUSE 50              ' SETTLE TIME
    		SEROUT2 TX, BAUD,["RUN",13]
    '		SEROUT2 TX, BAUD,[HEX CNT,13]
    	LOOP
    	DO WHILE SWITCH_OFF = 1    ' CHECK OFF PUSH BUTTON
    	   ' IF BUTTON PUSHED
            HIGH LED_OFF          ' OFF INDICATOR ON
    		LOW LED_RUN           ' RUN INDICATOR OFF
    		PAUSE 50              ' SETTLE TIME
    		SEROUT2 TX, BAUD,["OFF",13]
    '		SEROUT2 TX, BAUD,[DEC CNT,13]
    	LOOP
    LOOP
    Copy/Paste from MCS
    Code:
    ' 12F675 
    ' 09/05/2011  
    DEFINE OSC 4
    ' SET FOR INTERNAL OSC AND MCLRE OFF
    #CONFIG
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    
    ANSEL=%00000000         ' ADC SET FOR DIGITAL 
    CMCON=7                 ' COMPARATOR SET FOR DIGITAL
    SWITCH_OFF  VAR GPIO.1  ' PUSH BUTTON FOR PUMP OFF
    SWITCH_RUN	VAR	GPIO.2  ' PUSH BUTTON FOR PUMP ON  
    LED_RUN     VAR GPIO.0  ' INDICATE RUN SIGNAL SENT  
    LED_OFF     VAR GPIO.5  ' INDICAT STOP SIGNAL SENT
    TX          VAR GPIO.4  ' DATA SEND PIN
    BAUD        CON 18030	' 18030 = 600 BAUD
    
    START:     ' SEND OFF SIGNAL AT POWER UP
        PAUSE  1000
        HIGH LED_OFF  
        SEROUT2 TX, BAUD,["OFF",13]  
    DO  ' LOOP TO CHECK PUSH BUTTONS
    	DO WHILE SWITCH_RUN = 1     ' CHECK ON PUSH BUTTON
    	   ' IF BUTTON PUSHED
    		HIGH LED_RUN          ' RUN INDICATOR ON
    		LOW LED_OFF           ' OFF INDICATOR OFF
    		PAUSE 50              ' SETTLE TIME
    		SEROUT2 TX, BAUD,["RUN",13]
    '		SEROUT2 TX, BAUD,[HEX CNT,13]
    	LOOP
    	DO WHILE SWITCH_OFF = 1    ' CHECK OFF PUSH BUTTON
    	   ' IF BUTTON PUSHED
            HIGH LED_OFF          ' OFF INDICATOR ON
    		LOW LED_RUN           ' RUN INDICATOR OFF
    		PAUSE 50              ' SETTLE TIME
    		SEROUT2 TX, BAUD,["OFF",13]
    '		SEROUT2 TX, BAUD,[DEC CNT,13]
    	LOOP
    LOOP
    Last edited by mackrackit; - 14th September 2011 at 14:38.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    The problem lies with most of the IDEs/editors. They use a varying number of spaces for tabs - some allow users to specify the value. As Mr. E noted, most have a convert tabs to spaces function but the simplest thing to do is to make your various editors agree on how many spaces make a tab or always use spaces rather than tabs.

  7. #7
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    OK... I'll jump in here with a question

    In order to go back and reclaim those posts that were originally posted with HTML (when it was allowed)...

    Would it be possible to re-enable HTML, for a short time, then copy the code that was posted and paste back in the code, without the HTML, then dis-able the HTML??

    Thus re-covering the VALUABLE code examples that have for now been lost.

    This might entail a lot of manual work... but there are VALUABLE code examples, like LCD BARGRAPHS, that are currently unusable.

    I sure hate to see all those posts and thread lost.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  8. #8
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Nice neat code posts

    I always have MCSP set to "convert tabs to spaces". I tried to attach my source but, it didn't "take". I'll send you a link instead.

    http://dl.dropbox.com/u/566712/GetNumber_part.bas
    Charles Linquist

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts