' com_shell.pb — Shell COM automation simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL shellAppID AS LONG
    LOCAL fileIDs(50) AS LONG
    LOCAL fileSizes(50) AS LONG
    LOCAL fileTypes(50) AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL totalSize AS LONG
    LOCAL numFiles AS LONG
    LOCAL folderPath AS STRING
    LOCAL actionID AS LONG
    LOCAL actionCount AS LONG
    LOCAL fileID AS LONG
    LOCAL sz AS LONG
    LOCAL typeVal AS LONG
    LOCAL typeStr AS STRING

    PRINT "=== Shell COM Automation ==="

    shellAppID = 1
    PRINT "Shell application created: ID=" + STR$(shellAppID)
    PRINT "Windows: 3"

    folderPath = "C:\Documents"

    fileIDs(0) = 1
    fileSizes(0) = 45000
    fileTypes(0) = 1

    fileIDs(1) = 2
    fileSizes(1) = 120000
    fileTypes(1) = 2

    fileIDs(2) = 3
    fileSizes(2) = 3200
    fileTypes(2) = 3

    fileIDs(3) = 4
    fileSizes(3) = 250000
    fileTypes(3) = 4

    fileIDs(4) = 5
    fileSizes(4) = 8500
    fileTypes(4) = 5

    numFiles = 5
    totalSize = 0

    PRINT "Folder: " + folderPath + " Files: " + STR$(numFiles)
    FOR i = 0 TO numFiles - 1
        fileID = fileIDs(i)
        sz = fileSizes(i)
        typeVal = fileTypes(i)
        IF typeVal = 1 THEN typeStr = "DOC"
        IF typeVal = 2 THEN typeStr = "XLS"
        IF typeVal = 3 THEN typeStr = "TXT"
        IF typeVal = 4 THEN typeStr = "JPG"
        IF typeVal = 5 THEN typeStr = "BAS"

        IF fileID = 1 THEN PRINT "  [" + typeStr + "] report.doc (" + STR$(sz) + " bytes)"
        IF fileID = 2 THEN PRINT "  [" + typeStr + "] budget.xls (" + STR$(sz) + " bytes)"
        IF fileID = 3 THEN PRINT "  [" + typeStr + "] notes.txt (" + STR$(sz) + " bytes)"
        IF fileID = 4 THEN PRINT "  [" + typeStr + "] photo.jpg (" + STR$(sz) + " bytes)"
        IF fileID = 5 THEN PRINT "  [" + typeStr + "] script.bas (" + STR$(sz) + " bytes)"

        totalSize = totalSize + sz
    NEXT i
    PRINT "Total size: " + STR$(totalSize) + " bytes"

    FOR actionCount = 1 TO 5
        actionID = actionCount
        IF actionID = 1 THEN PRINT "  ShellExecute: open report.doc"
        IF actionID = 2 THEN PRINT "  ShellExecute: edit notes.txt"
        IF actionID = 3 THEN PRINT "  ShellExecute: print report.doc"
        IF actionID = 4 THEN PRINT "  ShellExecute: explore C:\Documents"
        IF actionID = 5 THEN PRINT "  ShellExecute: properties photo.jpg"
    NEXT actionCount

    PRINT "Shell app released"
    PRINT "=== End Shell ==="
    FUNCTION = 0
END FUNCTION
