Monitor TPS File Keys Building

Hi,
How do you handle the BUILDing task
With this code, i can’t see what it was done if any.
Any guidance please? Thank you.

    ?count{PROP:RangeHigh} = Records(Source)   
    TheYearJan1 = DATE(1, 1, Year(today()) )  
    Clear(PercentDone)
    Clear(KeyNameBeingRebuilt)
    Display

    Set(Source) 
    loop
        NEXT(Source)
        if errorcode() then break.
        if SRC:CheckDate >=  TheYearJan1   
            Clear(DES:record)
            DES:id = SRC:id
            Get(Destination,DES:KEYid)
            if errorcode()
                DES:record :=: SRC:record
                Append(Destination)
                AddCount += 1
            end       
        end
        count +=1
        if count % 4096 = 0 then 
            StateAppended = AddCount &' Records added ' & INT(AddCount/count*100) &' %' 
            Stateline    = count    &' Records read'          
            Elapsed = clock() - StartTime
            Display 
        end
    end

    StateAppended = 'Total of '& AddCount &' Records added'
    Destination{Prop:ProgressEvents} = 100
    PercentDone = Destination{PROP:Completed} 
    KeyrefBeingRebuilt = Destination{PROP:CurrentKey}
    KeyNameBeingRebuilt =  Destination{PROP:Label}
    BuildKeysDone = False 
    Display

    Build(Destination)
    if EVENT:BuildDone
        BuildKeysDone = True
        Display
    end
    

The help for PROP:ProgressEvents demonstrates that you can look for the build events inside the ACCEPT loop. I would review that help then construct the code in a way that you’re prepared to receive the events sent.

Here is some code I use in a lot of my apps

FileBuildKeys                 PROCEDURE (*FILE prmFile, STRING prmFileName, BYTE prmSilent=0)
wrkActionBuild                  CSTRING(81)
wrkKeyRef                       &KEY
wrkString                       StringTheory
WinBuild                        WINDOW('Building File Keys'),AT(,,330,22),FONT('Segoe UI',10,,),CENTER,GRAY, |
                                    DOUBLE
                                  PROMPT('Target:'),AT(4,2,31,10),USE(?prmFileName:Prompt),TRN
                                  STRING(@s100),AT(36,2,291,10),USE(prmFileName),TRN
                                  STRING(@s80),AT(4,12,323,10),USE(wrkActionBuild),TRN,CENTER
                                END

  CODE
    !-
    IF prmFile &= NULL
      RETURN
    END
    !-
    prmFileName  = wrkString.FileNameOnly(prmFileName)

    FLUSH(prmFile)
    !-
    IF prmSilent
      BUILD(prmFile)
      IF ERRORCODE()
        !Do something
      END
      RETURN
    END
    !-
    DISPLAY()
    YIELD  ()
    !-
    OPEN(WinBuild)
    !-
    ACCEPT
      CASE EVENT()
        OF EVENT:OpenWindow
          prmFile{PROP:FullBuild     } = True
          prmFile{PROP:ProgressEvents} = 50 !100 !50 !100
          BUILD(prmFile)
          IF ERRORCODE()
            !Do something
          END
          !----------------------------------------
        OF EVENT:BuildFile
          wrkActionBuild  = 'Building ' & prmFile{PROP:Completed} & '%'
          DISPLAY(?wrkActionBuild)
          !----------------------------------------
        OF EVENT:BuildKey
          wrkKeyRef &= prmFile{PROP:CurrentKey}
          IF wrkKeyRef &= NULL
            wrkActionBuild  = 'Building ' & prmFile{PROP:Completed} & '%'
          ELSE
            wrkActionBuild  = 'Building ' & prmFile{PROP:Completed} & '%  Key ' & wrkKeyRef{PROP:Label}
          END
          DISPLAY(?wrkActionBuild)
          !----------------------------------------
        OF EVENT:BuildDone
          wrkActionBuild  = 'Build Complete'
          DISPLAY(?wrkActionBuild)
          POST(EVENT:CloseWindow)
          !----------------------------------------
      END
    END
    !-
    CLOSE(WinBuild)
    !-
    prmFile{PROP:FullBuild     } = False
    prmFile{PROP:ProgressEvents} = 0
    !-
    wrkKeyRef  &= NULL
    !-
    DISPLAY()
    YIELD  ()
    !-
    RETURN
!==============================================================================
1 Like

Thank you @jslarve
The ACCEPT loop was the missing part.

@KevinErskine thank you for the provided code.
i don’t use third party tools/frameworks (StringTheory), i will pass parameters as usual and add a progress bar control to the window.

1 Like

Glad I could help. But as for 3rd party tools. Without a doubt the 1 product StringTheory has revolutionized my coding and efficiency. I love all Capesoft and BoxSoft tools and use several other saving me hundreds of hours. They are all source based products so they will never stop being useful even if the company goes out of business. I just compile and all is good. But to each their own.

3 Likes

The File Name is after the Last Backslash.

You can use INSTRING() to search in Reverse with a Step of -1, and a Start Pos of the End of the string i.e. Size(). For a PString or CString would more be correct to use Len() as there is oftem garbage after the defined length … so LEN() is always the safe choice.

prmFileName=SUB(prmFileName,1 + INSTRING('\',prmFileName, -1, SIZE(prmFileName)) , 999)
2 Likes