AUTOMATIC MENU

by Gordon Sweet
http://sionet.mysite.wanadoo-members.co.uk

As you know JB like LB needs around 3 Mb of support files to run even a single TKN, and if you want to distribute any of your creations, you must include all of these files in a package. So if you want to distribute a number of your TKNs it might appear you need to include all 3 Mb of files with each TKN. This can be a problem if downloading from a web site not only due to the web space involved, but in downloading time especially for those not on Broadband.

Some time ago I solved the problem by designing an automatic menu of all TKN files in the same directory as the menu. Not only does anyone interested in downloading any of my efforts only need to download the 3 Mb of runtime files once, but the files take up far less space, especially when in the past I was limited to only 15 Mb of web space for the site.

The JB version of the menu is set out below. You can see the only difference from the LB version is the latter is blessed with a nice SORT function, disabled here as a REM. If you experiment you will notice the menu only displays if more that one TKN is present apart from the JBmenu, and produces a NOTICE warning if there are no other TKNs present or some clever person attempts to activate the JBmenu again from the menu list. Note the procedure of creating a JBmenu.tkn and renaming a copy of JBRUN101.exe to JBmenu.exe. You can also include a note advising anyone who may only want to run one of your TKNs to rename this EXE file to match the required TKN and remove all others from the directory including JBmenu.tkm.

' Lists/Runs all TKN Files in same directory
' as this menu program, or starts a single TKN.
' Create a JBmenu.TKN, rename jbrun101.exe or previous
' versions as JBmenu.exe then activate it

    nomainwin
    dim item$(100) : dim dir$(10,3)
    File$ = Upper$("*.tkn")
    files "", File$, dir$()
    path$ = dir$(0, 2); dir$(0, 3)
    qtyFiles = val(dir$(0, 0))
    none$="NO TKN FILES TO BE RUN !!!"
    if qtyFiles < 2 then notice none$ : end
    if qtyFiles = 2 then [two]    ' ONLY 2 TKN FILES PRESENT
    if qtyFiles > 90 then
        notice "Reduced to the limit of Limit 90!"
        qtyFiles = 90             ' maximum displayable
    end if
    tl$ = "Menu of ";qtyFiles;" TKN files."

    count = qtyFiles             ' CALCULATE HEIGHT OF MENU
    height = int(count/5) * 30 + 40
    if int(count/5)<>count/5 then height = height + 30

    ux = 1 : uy = 1
    if DisplayWidth > 1000 then ux = 120 : uy = 90
    UpperLeftX = ux : UpperLeftY = 100 + uy
    WindowWidth = 800 : WindowHeight = height
    open tl$ for graphics_nsb_nf as #1
    #1 "trapclose [quit]; when leftButtonDown [which]; fill cyan"
    #1 "font fixedsys; backcolor darkblue; color yellow; down"

    for x = 1 to qtyFiles
        dir$(x, 1) = right$("        " + dir$(x, 1), 9)
    next x
    for x = qtyFiles to 1 step -1
        ts$ = left$(dir$(x, 0) + "            ", 50)
        ts$ = upper$(trim$(ts$))
        item$(x) = ts$
    next x
REM sort item$(), 1, qtyFiles ' ONLY WITH LB
    gosub [show]

[hold]
    #1 "redraw" : playwave "chord" ' INSTEAD OF beep
    wait

[show]
    y = 10 : C = 1 : endr = (count+4) / 5
    for row = 1 to endr : x = 4
        for colm = 1 to 5
            #1 "place ";x;" ";y
            #1 "boxfilled ";x+140;" ";y+20
            #1 "place ";x+10;" ";y+14
            #1 p$ : n = C - 1 + colm
            show$ = "\"+item$(n)
            ' SHOW PART OF LONG FILENAMES
            if len(show$)>16 then show$=left$(show$,16)
            #1 show$;
            x=x+160
        next colm
        x = 1 : y = y + 30 : C = C + 5
     next row
     #1 "flush" : return

[which]
    x=MouseX : y=MouseY       ' LEFT CLICK MOUSE POSITION
    if x < 4 or x > 780 then [hold]
    if y < 10 then [hold]
    A = 10 : B = 28 : L = -1
    for D = 1 to 19          ' CHECK MOUSE CURSOR VERTICALLY
        if y > A and y < B then L = D -1
        A = A + 30 : B = B + 30
    next D
    L = L * 5
    A = 5 : B = 142 : K = 0
    for D = 1 to 5           ' CHECK MOUSE CURSOR HORIZONTALLY
        if x > A and x < B then K = D
        A = A + 160 : B = B + 160
    next D
    if D = 0  or L < 0 or K = 0 then [hold] ' NO BUTTON SELECTED
    K = K + L                               ' VALUE OF BUTTON
    if K > count then [hold]                ' NO BUTTON SELECTED
    cf$ = item$(K)                          ' OPTION OF BUTTON
    if cf$="JBMENU.TKN" then notice "MENU ALREADY RUNNING" : goto [hold]
    run cf$, restore
    goto [hold]

[two]
    ' NO MENU NEEDED - FIND THE OTHER TKN
    for file = 1 to 2
    file$ = upper$(dir$(file,0))
        if file$ <> "JBMENU.TKN" then exit for
    next file
    run file$, restore
    end

[quit]
    close #1 : end