' i have three cd/rw drives attached to my computer and i sometimes
' (frequently) get confused as to which drive letter is associated
' with which drive. put a shortcut on the desk top and there you are.
'
' i thought i'd share this in the hopes somebody else might find it
' useful.
'
' note: if you press keys in rapid succession, there will be a considerable
' delay (several seconds) before the next cd tray toggles. i don't know
' why this is but it is.
'
' forgot to add: written in cc 3.04


Code:
$include "win32api.inc"                         '
    declare sub opentray                        '
    declare sub closetray                       '
    declare sub delay (single)                  '
    global cddrive as string                    '
                                                '
    function pbmain()                           '
    local drive as long                         '
    local a() as string                         '
    local i   as long                           '
    local x   as long                           '
                                                '
    color 14,1                                  '
    cls                                         '
    i = 0                                       '
    for drive = 65 to 90                        '<-: from a to z
                                                '  |
    if getdrivetype(chr$(drive) + ":\") = 5 then'<:|
    incr i                                      ' | |
    redim preserve a(i)                         ' | |
    a(i) = chr$(drive) + ":"                    ' | |
    end if                                      '<:|
                                                '  |
    next drive                                  '<-:
                                                '
    cls                                         '
    m$ = "cd drives detected. press the associated letter to toggle open/closed:"
    locate 1,1 : print;m$;                      '
    locate 3,1                                  '
    for x = 1 to i                              '
    print;a(x)                                  '
    next x                                      '
                                                '
    do                                          '<--:
    while instat = 0 : wend                     '   |
    an$ = inkey$                                '   |
    if an$ = chr$(27) then exit loop            '   | escape to end the program
    for x = 1 to i                              '<-:|
    if ucase$(an$) = left$(a(x),1) then         '<:| | if a key press matches
                                                ' | &#0124; &#0124;
    cddrive = a(x)                              ' | &#0124; &#0124;
    opentray                                    ' | &#0124; &#0124; open the tray
    delay 1                                     ' | &#0124; &#0124; wait for 1 second
    closetray                                   ' | &#0124; &#0124; then close it.
    exit for                                    ' | &#0124; &#0124;
    end if                                      '<:| |
                                                '  | |
    next x                                      '<-:|
    loop                                        '<--:
                                                '
    end function                                '
                                                '
' code modified from bob scott at               '
' [url="http://www.powerbasic.com/support/pbforums/showthread.php?t=15427"]http://www.powerbasic.com/support/pbforums/showthread.php?t=15427[/url] 

sub opentray
  mcisendstring "open " + cddrive + " type cdaudio alias cdname", ", %null,%null
  mcisendstring "set cdname door " + "open " + ", ",0,%null
  mcisendstring "close cdname", ",0,%null
end sub

sub closetray
  mcisendstring "open " + cddrive + " type cdaudio alias cdname", ", %null,%null
  mcisendstring "set cdname door " + "closed " + ", ",0,%null
  mcisendstring "close cdname", ",0,%null      '
end sub                                         '
                                                '
                                                '
sub delay(delaytime as single)                  '
    local starttime  as double                  '
    local endtime    as double                  '   time to finish
                                                '
    starttime = timer                           '
    endtime = starttime + delaytime             '   add the delay.
                                                '
    if endtime > 86400 then                     '<: wrap-around
    endtime = endtime - 86400                   ' | at midnight.
    end if                                      '<:
                                                '
    do until starttime => endtime               '   keep looping until.....
    starttime = timer                           '
    sleep 0                                     '
    loop                                        '
    end sub                                     '
------------------


[this message has been edited by mel bishop (edited february 02, 2007).]