Program for pending files from a particular folder in a directory Progress 4gl - progress-4gl

Program for pending files from a particular folder in a directory, that file need to be with specific extension like xml. If the files are pending more than 5, then send a mail alert. Someone please help me. I am a rookie in progress 4gl.

Code below will help you count the number of files in a folder.
You will need some way of sending e-mails, that's nothing that Progress comes shipped with.
There's an old library called smptmail.p that you might be able to find online. Possibly there are better solutions out there as well.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE iXmlFiles AS INTEGER NO-UNDO.
DEFINE STREAM str.
INPUT STREAM str FROM OS-DIR("c:\temp\").
REPEAT :
IMPORT STREAM str cFile.
IF cFile MATCHES "*.xml" THEN
iXmlFiles = iXmlFiles + 1.
END.
INPUT STREAM str CLOSE.
IF iXmlFiles >= 5 THEN
MESSAGE "Alert. There are " iXmlFiles "xml files" VIEW-AS ALERT-BOX WARNING.

Related

How to ignore error/exception during process of a list?

Learning kdb+q. Without loss of generality, let's say if I have a list of file paths and wants to open each one of them, but I want to make sure Q opens whatever it exists. Say if one of the file paths doesn't exist, then continue to process others.
I know protected evaluation can let me handle error #[open_many_files_func; files; errhandler].
But how to make it not fail in the middle and continue with the rest?
You can use 'each' to iterate over the files
#[open_many_files_func; ; errhandler] each files
If it's just existance of the file that you're checking for (and not that the function fails due to a problem with the file), then you could also use the key function to check the existance of the file.
q)system "ls"
"file1"
"file2"
"file4"
q)b: a where count each a: key each `:file1`:file2`:file3`:file4
`:file1`:file2`:file4
Once you have the list of files, you can just do
open_many_files_func each b
https://code.kx.com/q/ref/key/

How to print image in output stream?

Is it possible to print some text + image with 4GL? I tried several approaches and nothing works for me. My code is below
DEFINE VARIABLE mMyMemPtr AS MEMPTR NO-UNDO.
FILE-INFO:FILE-NAME = "C:\image.png".
SET-SIZE(mMyMemPtr) = FILE-INFO:FILE-SIZE.
INPUT FROM VALUE(FILE-INFO:FILE-NAME) BINARY NO-MAP NO-CONVERT.
IMPORT mMyMemPtr.
INPUT CLOSE.
OUTPUT STREAM printstream TO PRINTER.
PUT "some text: " AT 1 SKIP.
PUT mMyMemPtr.
OUTPUT CLOSE.
Yes and no. It's possible to print images with ABL/Progress 4GL but not that way. You will need some other technique. The easiest way is probably to look into some kind of document format that supports printing. For example creating and printing:
a Word document via ActiveX automation (start here: https://knowledgebase.progress.com/articles/Article/P20445)
an HTML document
a PDF (there are freeware PDF-tools for Progress like the outdated http://www.oehive.org/pdfinclude.html - possibly others as well) or PostScript document
Via any report generator like Crystal, Eclipse BIRT etc.

Way of checking if a bookmark exists from SAS using DDE connection to Word

I am using SAS v9.4, running a DDE connection to Word 2010.
Once I have connected to a word document, I would like to be able to check from withing SAS whether a specific bookmark exists or not. Is this possible withing the DDE framework?
I have tried adding the if statement, but it looks like the command Bookmarks.Exist isn't recognised.
filename sas2word dde 'winword|system';
data _null_;
file sas2word;
if put '[Bookmarks.Exists("Bkm1")]' then do;
put '[EditGoTo.Destination = "Bkm1"]';
put '[Insert "Test"]';
end;
run;
But it just crashes and comes up with.
"The Bookmark does not exist"
Is there a way to query the Word document so we can avoid the pop-up/crash? Or, if not, is there a way to run a try-catch loop within the code so it keeps running?
Also sorry if the tags are not accurate, wasn't sure exactly what this question fell under so I tagged all three options - feel free to edit if inappropriate.

How to decode HEX code to regular text in Apple Script

I'm using the todo list app Things from Cultured Code on my Mac and when I copy a link to a task to clipboard it ends up encoded as HEX code in the clipboard. No problem when I paste it into a text file – it then shows as decoded text.
But, I need to use the clipboard content in an AppleScript and have difficulties decoding it to plain text there.
I have tried multiple subroutines but they did not work in my case. Most examples that I found online deal with simple encoded URLs. And the code that I have so far works to decode for example "0348" correctly to the number 1000 but my script cannot decode the encoded Things link (that long line of numbers at the top).
Can somebody help me please?
Here's what I have so far:
-- The link to a task in THINGS, encoded: 7468696e67733a2f2f2f73686f773f69643d41463645303746462d394230462d343539332d423143332d313846303337434237363836
-- Above link to the task in THINGS, unencoded: things:///show?id=AF6E07FF-9B0F-4593-B1C3-18F037CB7686
-- Online converter: http://www.unit-conversion.info/texttools/hexadecimal/
-- Number 1000 encoded: 03E8
set theEncodedText to "03E8"
set theDecodedText to (do shell script "perl -e 'printf(hex(\"" & theEncodedText & "\"))'") as string
set theDisplayedText to theDecodedText
display dialog theDisplayedText
Thank you,
Martin
The following example AppleScript code is a proof of concept of how I'd handle setting to a variable a Things URL link that's saved to the clipboard as «data url ...» where ... is Hex Data.
This script writes the «data url ...» to a temporary file, reads the temporary file, which is now a text string of the «data url ...», and sets it as a the value of a variable, and then deletes the temporary file. It then displays the Things URL link as a text string or displays a message that the clipboard did not contain a 'things:///show?id=' URL link.
Example AppleScript code:
if ((clipboard info) as string) contains "URL" then
set thingsURL to "/tmp/thingsURL.tmp"
try
set f to open for access thingsURL with write permission
set eof f to 0
write (the clipboard) to f
close access f
on error
close access f
end try
set thingsURLtext to (read thingsURL)
tell application "System Events" to delete file thingsURL
display dialog thingsURLtext buttons {"OK"} default button 1
else
display dialog "The clipboard did not contain a 'things:///show?id=' URL link." buttons {"OK"} default button 1
end if
Note: The example AppleScript code is just that and does not employ any other error handling then what's shown and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.

How to generate new numbers if i run the program everytime from the begining?

I am working on CATScript in optimization of a part.
When I run the script everytime it shoud provide numbers in ascending order.
For example if I run the program for the first time it should provide the output as " 1 "
and if I run the program again it shoud provide the output as " 2 " and so on.
I am stuck with this and I could not figure out th logic that we have to use here.
Looking forward for your help.
Thank you!!
An option (matlab based) could be to save a counter variable to a .mat-file at the end of the script, which is then loaded again at the beginning of the script.
That would allow you to keep track of how many times the script have been run.
In CATIA if it is being run multiple times on the same part/product, you could add a hidden, integer parameter to the specification tree and increment it each time the macro is run.
Another, more generic way would be to create a text file on the user's local and update the number in the text file.