Announcement

Collapse
No announcement yet.

Msrginal Notes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Msrginal Notes

    1.0 Is there any / a rule set for the (left margin) placement of PBCC code entries, or is this left to the discretion of the person doing the coding?
    2.0 Presuming the latter, have any of you settled on some convention that works pretty well for you; (like TAB counts) OR, is this question just getting too nit-picky as it has to be situation-dependent? For me, I can get along without it, but I wouldn't be offended by anyone's suggestions. Thank you for your thoughts.

  • #2
    Do you mean the indent for block commands? (like IF/ELSE/END IF, SELECT CASE, etc.)
    The person doing the coding. The IDE default is 4 spaces. I set mine to 2 spaces so I don't get to character 80 on the right too soon. (another personal preference to avoid horizontal scrolling on non-wide windows)

    Cheers,
    Dale

    Comment


    • #3
      1.0 Entirely personal preference.
      2.0 Personally, I use four characters as my default tab indentation for all blocks.

      Compiler directives, equates, globals etc and Function/Sub and End Function/End Sub are all in the first column, everythiing else is indented.
      I also indent continuation lines.

      Here's my basic DDT template which shows my standard.

      '
      Code:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE ONCE "WIN32API.INC"
      
      ENUM ctrls SINGULAR
          IDC_Quit = 1001
      END ENUM
      
      FUNCTION PBMAIN() AS LONG
          MainDLg 0
      END FUNCTION
      
      FUNCTION MainDlg (hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW hParent, "Std Dialog", , , 150, 100, %WS_POPUP OR %WS_BORDER _
              OR %WS_DLGFRAME OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
              %DS_MODALFRAME, TO hDlg
      
          CONTROL ADD BUTTON , hDlg,%IDC_quit,"Quit",40,70,80,20
      
          DIALOG SHOW MODAL hDlg, CALL MainDlgCB TO lRslt
      END FUNCTION
      
      CALLBACK FUNCTION MainDlgCB()
      
          SELECT CASE AS LONG CB.MSG
              CASE %WM_INITDIALOG
      
              CASE %WM_NCACTIVATE
                  STATIC hWndSaveFocus AS DWORD
                  IF ISFALSE CB.WPARAM THEN
                      hWndSaveFocus = GetFocus()
                  ELSEIF hWndSaveFocus THEN
                      SetFocus(hWndSaveFocus)
                      hWndSaveFocus = 0
                  END IF
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CB.CTL
                      CASE %IDC_QUIT
                          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                              DIALOG END CBHNDL
                           END IF
                  END SELECT
          END SELECT
      END FUNCTION
      '
      :

      Comment


      • #4
        The criterion that I suggest is the most useful is whether you can quickly read the code you have written. You can turn a tangled mess into more or less readable code with indenting and spacing and while what works for your eye is the best solution, if it has to be read by someone else some time down the track, I would find a way to make it easily readable for them.

        Long ago I had to use some PHP that was posted on the internet and this dill was using tab stops of either 8 or 12 space equivalent and it ran right off the right side of the screen. To use it I had to write a utility that fixed the formatting just so I could read it. I format much the same as Dale, 4 spaces from the left side of the editor with 2 space indents which can be nested to a reasonable depth without running off the screen. My 1920 x 1080 screen size has plenty of room for all but the most extreme nesting and I use a reverse nesting if that happens.

        This is a sample of my preferred style of indentation and you can apply any style of variation that suits how you write code.
        Code:
        ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
        
        FUNCTION DlgProc(ByVal hDlg   as DWORD, _
                         ByVal uMsg   as DWORD, _
                         ByVal wParam as LONG, _
                         ByVal lParam as LONG) as DWORD
                          
            Select Case as LONG uMsg
              Case %WM_INITDIALOG
                SendMessage hDlg,%WM_SETICON,1,LoadIcon(hInstance,ByVal 5)
                SetWindowText hDlg,"Single Instance Dialog"
        
              Case PM_ACTIVATE
                SetForegroundWindow hDlg
                msgbox "hi"
        
              Case %WM_COMMAND
                Select Case as LONG wParam
                  Case 100
                    MsgboxI hDlg,"Memory Dialog Template    ","About",%MB_OK,5
                  Case 101
                    EndDialog hDlg, 1           ' return value to original dlg caller
                End Select
        
              Case %WM_SYSCOMMAND
                Select Case as LONG wParam
                  Case %SC_CLOSE
                  EndDialog hDlg, 0             ' return value to original dlg caller
                End Select
        
            End Select
        
        END FUNCTION
        
        ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
        hutch at movsd dot com
        The MASM Forum

        www.masm32.com

        Comment


        • #5
          1. It's up to each and everyone. I use 2 character positions from left margin for code entries, while I know many (most?) use 4.

          2. Because of answer to Q 1, I have changed Options/Editor/Auto Indent - Tab Size from 4 (default) to 2. Inside code like between IF/THEN, etc, I still usually use 4 character positions, meaning I have to press TAB twice. No, I don't understand why I do that either, probably just some old habit I have gotten used to over ther years. Aside from that, I place FUNCION/SUB, END FUNCION/SUB, Labels and delclarations at top/beginning of code at far Left.

          Comment


          • #6
            It may depend a bit on the size of font that you use in the editor, I use a size 12 whereas others may not go that large but if I was using a smaller font size I would set it to 4 space indenting. Like Walt, I use 2 space indenting because I have my monitor in portrait mode but that still gives me over 100 characters in width. There are some that use 3 spaces.
            Rod
            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

            Comment


            • #7
              I have started using 2 characters and GOSUB to keep the tab count down. Some may say don't use GOSUB but it makes the code more readable.
              Code:
              #COMPILER PBWIN
              #COMPILE EXE "Program1.Exe"
              #DIM ALL
              
              #INCLUDE "Win32API.Inc" 'PB or JR includes
              
              ENUM MyEquates SINGULAR
                ID_Button = %WM_APP +1
              END ENUM
              
              '************************************************************
              FUNCTION PBMAIN() AS LONG
              '************************************************************
                LOCAL hDlg AS DWORD
                LOCAL lDebug AS LONG: TXT.WINDOW "Debug", 10,10,50,50 TO lDebug '(x,y,h,w) Thanks Dave!
              
                DIALOG NEW PIXELS, %HWND_DESKTOP, EXE.NAME$, _
                                   %CW_USEDEFAULT,%CW_USEDEFAULT,300,300, _
                                   %WS_OVERLAPPEDWINDOW,0 TO hDlg
                CONTROL ADD BUTTON, hDlg, %ID_Button, "Press", 10,10,50,20
                TXT.PRINT "hDlg=" & HEX$(hDlg)
              
                DIALOG SHOW MODAL hDlg CALL PBProc
              END FUNCTION
              
              '************************************************************
              CALLBACK FUNCTION PBProc() AS LONG
              '************************************************************
                STATIC ID_SendHandle AS DWORD
                STATIC ID_SendData   AS DWORD
                STATIC hProgram2     AS DWORD
              
                LOCAL ProcessID AS LONG
                LOCAL CDS       AS COPYDATASTRUCT
                LOCAL pCDS      AS COPYDATASTRUCT PTR
                LOCAL sPass     AS STRING
              
                SELECT CASE LONG CB.MSG
                CASE %WM_INITDIALOG: GOSUB WM_InitDialog
                CASE %WM_COMMAND:    GOSUB WM_Command
                CASE ID_SendHandle:  GOSUB SendHandle
                CASE %WM_COPYDATA:   GOSUB WM_CopyData
                END SELECT
                EXIT FUNCTION
              
              '************************************************************
              WM_InitDialog:
              '************************************************************
                'when this program starts, ask for the 2 WindowMessages
                'we are going to use.
              
                ID_SendHandle = RegisterWindowMessage("SendHandle")
                ID_SendData = RegisterWindowMessage("SendData")
                IF ISFALSE(ID_SendHandle) OR ISFALSE(ID_SendData) THEN
                  ? "RegisterWindow Failed", %MB_ICONERROR, EXE.NAME$
                  DIALOG END CB.HNDL, 0
                END IF
                RETURN
              
              '************************************************************
              WM_Command:
              '************************************************************
                'when the button is pressed it will shell to Program2 and
                'pass our handle as a decimal string to it. Program2 will
                'use this to send back its handle.
              
                SELECT CASE LONG CB.CTL
                CASE %ID_Button
                  IF ISFILE("Program2.Exe") THEN
                    ProcessID = SHELL("Program2.Exe " & DEC$(CB.HNDL))
                  ELSE
                    ? "Compile Program2 first", %MB_ICONERROR, EXE.NAME$
                  END IF
                END SELECT
                RETURN
              
              '************************************************************
              SendHandle:
              '************************************************************
                'when Program2 starts it will respond with its handle
                'so we can send our test string to it using COPYDATA.
              
                hProgram2 = CB.LPARAM
                TXT.PRINT "hProgram2=" & HEX$(hProgram2)
              
                sPass = "Passed from " & EXE.NAME$
                CDS.dwData = ID_SendData
                CDS.cbData = LEN(sPass)
                CDS.lpData = STRPTR(sPass)
                TXT.PRINT "Result=" & DEC$(SendMessage(hProgram2, %WM_COPYDATA, CB.HNDL, VARPTR(CDS)))
                RETURN
              
              '************************************************************
              WM_CopyData:
              '************************************************************
                'in response to sending our test string to Program2 we will
                'get back a similar test string proving we have communications
                'in both directions.
              
                pCDS = CB.LPARAM
                IF @pCDS.dwData = ID_SendData THEN
                  TXT.PRINT "Received WM_COPYDATA"
                  TXT.PRINT ".dwData=" & HEX$(@pCDS.dwData)
                  TXT.PRINT ".cbData=" & DEC$(@pCDS.cbData)
                  TXT.PRINT ".lpData=" & PEEK$(@pCDS.lpData, @pCDS.cbData)
              
                  'We can also send a result code to Program2
                  FUNCTION = 1234
                ELSE
                  ? "Invalid SendData message received", %MB_ICONERROR, EXE.NAME$
                END IF
                RETURN
              END FUNCTION

              Comment


              • #8
                Of course we are all posting examples of PBWin code in the PBCC forum...

                Comment


                • #9
                  I like the way you do it, Frank. Very clean and easy to follow flow and maintain code. I too use GOSUB/RETURN a lot - very fast and pretty much what happens at a lower level anyway.

                  Comment


                  • #10

                    > Of course we are all posting examples of PBWin code in the PBCC forum...

                    Comment


                    • #11
                      Indents must be 4 for me too. When code runs off the right hand side of the screen I catch it in an old chad hopper to keep my desk tidy.

                      Comment


                      • #12
                        To answer the question:

                        Spaces are required before and after keywords, but multiple spaces are considered a single space by the compiler. Addiutional Spaces between function options are ignored as well.

                        The only required physical formatting of code required is new lines for multiline statements.

                        (Contrast witht COBOL... which IGNORES new lines and goes strictly by explicit punctuation characters eg.

                        Code:
                             IF  B > C  THEN GOTO NEW-PARA ELSE  MOVE 2 TO D
                        .. is exactly the same as
                        Code:
                        IF B > C THEN
                               GO TO NEW_PARA
                        E:LSE
                                  MOVE 2 TO D
                        ... and also to
                        Code:
                             IF
                             B
                             GREATER
                             C
                             GOTO
                             NEW-PARA
                             ELSE
                             MOVE
                             2
                             D
                        The physical line breaks are ignored.

                        NOTE "THEN" is optional in an IF . statement. "TO" is optional in a MOVE statement.
                        MOVE = Assignment: ==> MOVE source-value//variable [TO] destination-variable

                        In some compilers, "GOTO" may be shortened to "GO" (as it may be omitted in BASIC following THEN))

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Originally posted by Borje Hagsten View Post

                          > Of course we are all posting examples of PBWin code in the PBCC forum...
                          Unless it's Python* ( spit,spit!) the concept is the same regardless of specific language.

                          * or https://www.whoishostingthis.com/res...e-programming/

                          Comment


                          • #14
                            Thank You !! You guys are great !! (ne ar (and all are smarter than !!)

                            ~~dmj

                            Comment

                            Working...
                            X