PDA

View Full Version : Need help on solving Drive Action problem!


mdxafx
01-13-2007, 12:20 PM
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
01-13-2007, 01:03 PM
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

mdxafx
01-13-2007, 01:27 PM
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?

RizlaUK
01-13-2007, 01:34 PM
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

mdxafx
01-13-2007, 01:44 PM
Thanks RizlaUK

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

RizlaUK
01-13-2007, 01:48 PM
np problem, it took me a while to get my head round

mdxafx
01-13-2007, 07:20 PM
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!:)

RizlaUK
01-13-2007, 07:26 PM
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