Need help on solving Drive Action problem!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mdxafx
    Forum Member
    • Nov 2006
    • 13

    Need help on solving Drive Action problem!

    Read so much on the Drive. Functions that its making me ill.

    What im trying to is simple but my error codes i can't figure out.

    All it is:
    1. Get a list of Drive on the computer
    2. Get the type of Drives from the List of Drives, e.g( 5 == CD-ROM)
    3. Check the type to see if Drive == 5 (CD-ROM)
    4. If they are Type 5 then get the Display Name from the drive
    5. If the Display name =="" no string Label then
    6. Eject each of the Drive/s!

    In over word check to see if each drive(CD-Rom) has a Disc
    in it!

    Here the code i've been working on:-

    -----------------------------------------------------------------------

    --Generate Drive List
    GenerateDrivesL = Drive.Enumerate();


    --Index Drive List
    for i, DrivesList in GenerateDrivesL do

    --Check Drive Type from list
    WhichDrive = Drive.GetType(DrivesList);

    -- See if drive type == 5 (CD-ROM Drives)
    if WhichDrive == 5 then

    --Check CD-ROM Drive Display name
    Output = Drive.GetInformation(DrivesList).DisplayName;

    --If the string is blank eject the drives!!
    if Output == "" then

    Drive.Eject(CDDVD);

    end

    end


    -------------------------------------------------------------
    my error displays:

    Output = Drive.GetInformation(DrivesList).DisplayName;

    is attempting to Index a Nil value!

    Thanks in advance for looking at the code!
    mdxafx
  • RizlaUK
    Indigo Rose Customer
    • May 2006
    • 5478

    #2
    right, its because Drive.GetInformation returns a error when there is no disk in the drive, so you have to use the error to trigger the event


    tDrives = Drive.Enumerate();
    for index in tDrives do
    nDriveType = Drive.GetType(tDrives[index]);
    if nDriveType == 5 then
    tDriveInformation = Drive.GetInformation(tDrives[index])
    error = Application.GetLastError();
    if (error ~= 0) then
    Drive.Eject(tDrives[index]);
    else
    result = Dialog.Message("Notice", "there is a disk in the drive", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    end
    end
    hope it helps
    Embrace change in your life, you never know, it could all work out for the best

    Comment

    • mdxafx
      Forum Member
      • Nov 2006
      • 13

      #3
      Surely if im using an (if) statement to test to see if the varible (Output) contains any string ("") should work for each drive!


      there should be no error until the (if) statement is called!
      I thought?

      Comment

      • RizlaUK
        Indigo Rose Customer
        • May 2006
        • 5478

        #4
        yeah, but the fact that you are useing "if" means that it is calling the event to check the condition and the if statment returns a error or nil if is there is no information to return

        in this case, if there is no disk in the drive "Drive.GetInformation" will return a error because there is no information to return, so you use the error the check the condition

        try my code
        Embrace change in your life, you never know, it could all work out for the best

        Comment

        • mdxafx
          Forum Member
          • Nov 2006
          • 13

          #5
          Thanks RizlaUK

          i see, Drive.GetInformation send an error because there
          is no information to be given from those drives!

          Comment

          • RizlaUK
            Indigo Rose Customer
            • May 2006
            • 5478

            #6
            np problem, it took me a while to get my head round
            Embrace change in your life, you never know, it could all work out for the best

            Comment

            • mdxafx
              Forum Member
              • Nov 2006
              • 13

              #7
              Hi RizlaUK,

              i was doing some tests earlier and found that the following also
              works, without using GetLastError. It basically just see if
              Drive.GetInformation() has a value in it!


              tDrives = Drive.Enumerate();
              for index in tDrives do
              nDriveType = Drive.GetType(tDrives[index]);
              if nDriveType == 5 then
              tDriveInformation = Drive.GetInformation(tDrives[index]);
              --error = Application.GetLastError();
              --if (error ~= 0) then
              if tDriveInformation == nil then
              Drive.Eject(tDrives[index]);

              else

              Dialog.Message("Notice", "there is a disk in the drive", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

              end
              end
              end


              Thanks for all your help!

              Comment

              • RizlaUK
                Indigo Rose Customer
                • May 2006
                • 5478

                #8
                yeah, like i said, it returns a error or nil, i just had problems getting the "nil" bit to work for me, guess i formatted it wrong

                cheers for the heads up :yes
                Embrace change in your life, you never know, it could all work out for the best

                Comment

                Working...
                X