Author Topic: Code-Formatter PB 10  (Read 158588 times)

0 Members and 1 Guest are viewing this topic.

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #180 on: January 12, 2012, 09:10:45 PM »
Hello
 here times a picture of new version.  Become the source code however only post whom everything well runs

 greetings Peter
« Last Edit: January 12, 2012, 09:17:51 PM by Peter Weis »

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #181 on: January 13, 2012, 12:14:59 PM »
Hello, 
changed the functions Is_Space, RebuildLine and inserted the keyword ASMDATA. That was not considered up to now!

However not yet the version is 3. Still the old version is 2. With it can be worked however already well!

Greet Peter   

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #182 on: January 13, 2012, 03:04:18 PM »
Peter,

I do not mean to belittle your programming skills. That is NOT my intention.
As we can never meet face to face or talk, the only way I can try to motivate you is via this forum.
If I had never made the type of remarks that I made,  would you have worked on a better version?
Or would you have sat back and waited for someone else to fix the problems?

I do have a couple hints for you.
Move all your static variables in DoFormat.inc into the fmtcommon udt.
Where you set them to 1  try incrementing them. This will allow for nested conditions.
Where you set them to 0  try decrmenting them but don't go lower than 0 as that means
you have a logic error and the reason should be fixed.
Make sure that if you increment a variable for a specific reason that you have a check that
is the end of that specific reason and decrment it.
..  for example if you flag the start of a Class then you must check for End of Class.

It is still a good idea to move the check for #PBForms down into RebuildLine. No need to
clutter up a huge section of code for a simple check.

Good programming!


Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #183 on: January 13, 2012, 04:29:11 PM »
Hello Paul,
 you can change it at any time the program code. Put the changed code then simply on the forum! Then we can find a common basis! Isolating the functions Is_Space and and RebuildLine must be! Because some macros with RebuildLine not to go can. Whom I take and into RebuildLine am #PBForms from DoFormat! then I must write it also once again in Is_Space!
And on the topic Class! The end of the Class is tested! See here

Code: [Select]
CASE "END"
            findPBWord s1, p, pbword, termstr
            SELECT CASE pbword
                CASE "FUNCTION", "SUB", "FASTPROC", "METHOD", "PROPERTY", "IF", "TYPE", "UNION", "TRY", "ASMDATA"
                    Einzug += - 1
                CASE "SELECT"
                    IF cflag THEN
                        einzug += - 2
                    ELSE
                        Einzug += - 1
                    END IF
                    cflag = %TRUE
                CASE "MACRO"
                    Einzug += - 1
                    cmacro = %FALSE
                CASE "INTERFACE"
                    Einzug += - 1
                    cinterface = 0
                CASE "CLASS"
                    Einzug += - 1
                    cclass = %FALSE
            END SELECT                 

 in addition is the result crucial! See here!


Code: [Select]
#COMPILE DLL
#DIM ALL
#RESOURCE "collection.pbr"
#COM DOC "Dies ist ein Test"
#COM NAME "Collection", 1.1
#COM GUID GUID$( "{85AF93DB-EF37-4916-BE38-CE32985B9C63}")
#COM TLIB ON

%LIST_MODULES_ALL                 = %LIST_MODULES_32BIT AND %LIST_MODULES_64BIT



#IF NOT %DEF(%CCOLLECTIONINC)
    %CCOLLECTIONINC               = 1


    INTERFACE ICollectionEvent GUID$( "{BC0DA08D-A429-42E7-BEC2-0FC5C56C131F}") AS EVENT
        INHERIT IAUTOMATION
        METHOD BevoreAdd(BYVAL nCount AS DWORD)


        METHOD AfterAdd(BYVAL nCount AS DWORD)


        METHOD ItemRemoved(oKey AS VARIANT)


        METHOD ERROR(BYVAL nNumber AS DWORD)

    END INTERFACE


    CLASS CCollection GUID$( "{BE08C50D-1D02-4A0A-8FA6-514E365B848F}") AS COM
        INSTANCE arObj()                AS VARIANT
        INSTANCE arKey()                AS STRING
        INSTANCE nCounter               AS DWORD

        CLASS METHOD DESTROY()
            ERASE arObj()
            ERASE arKey()
        END METHOD

        CLASS METHOD GetArIndex(sKey AS STRING) AS DWORD
            LOCAL    i                  AS DWORD
            ARRAY SCAN arKey(), COLLATE UCASE, = sKey, TO i
            METHOD = i
        END METHOD

        CLASS METHOD RemoveFromObjAr(BYVAL nIndex AS DWORD)
            LOCAL    i                  AS DWORD

            FOR i = nIndex TO UBOUND(arObj())
                IF nIndex > 0 THEN
                    SWAP arobj(i - 1), arobj(i)
                    SWAP arKey(i - 1), arkey(i)
                ELSE
                    IF i < UBOUND(arObj()) THEN
                        SWAP arobj(i), arobj(i + 1)
                        SWAP arKey(i), arKey(i + 1)
                    ELSE
                        i = 1
                    END IF
                END IF
            NEXT

            IF nCounter - 1 = 0 THEN
                REDIM    arobj(nCounter - 1)
                REDIM    arKey(nCounter - 1)
            ELSE
                REDIM    PRESERVE arobj(nCounter - 1)
                REDIM    PRESERVE arKey(nCounter - 1)
            END IF
        END METHOD

        INTERFACE ICollection GUID$( "{F975C92B-988F-4FA8-9BBA-6762C27014A7}")
            INHERIT IDISPATCH

            PROPERTY GET COUNT() AS DWORD
                PROPERTY = nCounter
            END PROPERTY

            PROPERTY GET GetKey(BYVAL nIndex AS DWORD) AS STRING
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arKey(nIndex)
            END PROPERTY

            PROPERTY GET GetItemDirect(BYVAL nIndex AS DWORD) AS VARIANT
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arObj(nIndex)
            END PROPERTY


            METHOD ADD(BYVAL obj AS VARIANT, OPT BYVAL oKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING

                RAISEEVENT ICollectionEvent.BevoreAdd(nCounter)
                IF ISMISSING(oKey) THEN oKey = STR$(nCounter + 1)

                SELECT CASE VARIANTVT(oKey)
                    CASE %VT_BSTR: s = UCASE$(VARIANT$(oKey))
                    CASE ELSE: s = STR$(VARIANT#(oKey))
                END SELECT

                IF me.GetArIndex(s) > 0 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF

                nCounter += 1
                REDIM    PRESERVE arObj(nCounter)
                REDIM    PRESERVE arKey(nCounter)
                arObj(nCounter) = obj
                arKey(nCounter) = s

                RAISEEVENT ICollectionEvent.AfterAdd(nCounter)
                METHOD = nCounter
            END METHOD

            METHOD Remove(BYVAL nItemOrKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE %VT_BSTR: s = UCASE$(VARIANT$(nItemOrKey))
                    CASE ELSE
                        n = VARIANT#(nItemOrKey)
                        Me.RemoveFromObjAr(n)
                        nCounter -= 1
                        METHOD = n
                        RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                        EXIT METHOD
                END SELECT
                n = me.GetArIndex(s)
                IF n < 1 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF
                Me.RemoveFromObjAr(n)
                nCounter -= 1

                RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                METHOD = n
            END METHOD

            METHOD ITEM(BYVAL nItemOrKey AS VARIANT) AS VARIANT
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE %VT_BSTR
                        s = UCASE$(VARIANT$(nItemOrKey))
                        n = Me.GetArIndex(s) - 1
                        IF n > 0 THEN METHOD = arObj(n)
                        EXIT METHOD
                    CASE ELSE
                        METHOD = arObj(VARIANT#(nItemOrKey))
                        EXIT METHOD
                END SELECT
                RAISEEVENT ICollectionEvent.Error(2)
            END METHOD


        END INTERFACE

        EVENT SOURCE ICollectionEvent
    END CLASS
#ENDIF

                                                             

Greet Peter 

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #184 on: January 13, 2012, 05:03:39 PM »
Peter,

#PBForms should not change any other line or indentation or function.
Plain & simple it starts in column 1. Print it & forget it.


Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #185 on: January 13, 2012, 06:12:12 PM »
Hello Paul
 #PBFORMS begins in the first column.  Therefore in function in DoFormat and not in Is_Space and RebuildLine!
 

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #186 on: January 13, 2012, 07:47:45 PM »
It only needs to be in 1 routine RebuildLine along with ALL the other PB keywords.
Otherwise you must document every exception and where they are found and why.

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #187 on: January 13, 2012, 08:17:58 PM »
Hello Paul,
 that I to also wish however it not function not, with all macros that already tested myself I!
Line2Words deletes all blanks!  And RebuildLine does not add blanks in addition where to be may.  That cannot be done with some macros any longer and the compilers brings then an error!
Therefore also the option inserts blanks!



Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #188 on: January 13, 2012, 08:58:31 PM »
Hello Paul, 

has now macro searched with the RebuildLine does not go and also not to go cannot! It does not insert a blank where be may!
Code: [Select]
MACRO WR_MM(P1,P2,P3)=P2=P1.nRight:P3=P1.nBottom
RebuildLine inserts a blank after after comma of P1. That macro does not function thereafter any longer! Ask Theo. Therefore also the option with inserts blanks. Around to go around the function Is_Space was inserted

greetings Peter

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #189 on: January 14, 2012, 12:42:58 PM »
Peter,

If you need to bypass rebuilding a certain line then look at the top part of Line2Words and
RebuildLine.
There are already a couple others that skip rebuilding.
That makes it neat & clean and easily understood.

BUT beware. For MACROs you might need to do several lines and not all will start with Macro.

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #190 on: January 14, 2012, 01:29:38 PM »
Paul, 
is a good idea! then make that times! But the introduction must remain! Only the blanks may not be worked on!

I am busy straight with the IDE of Version 3!

Greet Peter 
« Last Edit: January 14, 2012, 01:54:05 PM by Peter Weis »

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #191 on: January 14, 2012, 02:50:49 PM »
Peter,

It is up to you to make the changes. Not me.

You don't like the way that I program.


Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #192 on: January 14, 2012, 04:54:50 PM »
By the way this code works spaced out or without spaces.
I just tried it in PB v10.

Code: [Select]
TYPE dotit
   a AS LONG
   b AS LONG
END TYPE

MACRO ab(p1 , p2 , p3) = p2 = p1.a: p3 = p1.b
FUNCTION PBMAIN () AS LONG
   LOCAL dots AS dotit
   LOCAL a AS LONG
   LOCAL b AS LONG

   dots.a = 5
   dots.b = 7
   ab(dots,a,b)
   ? "a =" & STR$(a) & "  b =" & STR$(b)     

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 326
  • User-Rate: +15/-4
Re: Code-Formatter PB 10
« Reply #193 on: January 14, 2012, 10:04:39 PM »
Paul, 
you errs! That   Macro does not go! RebuildLine adds after the comma   a blank with the call!

You have the blank simply out calmly then already function it!

Attention blank with the call macros and not in the macro!!

Code: [Select]
#COMPILE EXE
#DIM ALL

MACRO ab(p1 , p2 , p3) = p2 = p1.a: p3 = p1.b

TYPE dotit
   a AS LONG
   b AS LONG
END TYPE

FUNCTION PBMAIN () AS LONG

   LOCAL dots AS dotit
   LOCAL a AS LONG
   LOCAL b AS LONG

   dots.a = 5
   dots.b = 7
   ab(dots,a,b)    ' this go
   
   ab(dots, a, b)  ' this not    Compiler Error

END FUNCTION

                               

Offline Paul Elliott

  • Full Member
  • ***
  • Posts: 164
  • User-Rate: +40/-32
Re: Code-Formatter PB 10
« Reply #194 on: January 14, 2012, 10:55:02 PM »
Then it is up to you to keep track of every Macro and make sure that where they are used
is not reformatted. Don't forget to check for multiple macros within a line and nested macro
definitions.