View Full Version : Can two nil values be compared from a table?
mdxafx
01-14-2007, 09:30 AM
Hi all,
was on the forum last night finding out why my Eject if no
cd in drive functions would not work. My new problem is
that if there is a Cd in one of the drive then don't eject the other
one.
The only trouble is that Drive.GetInformation will return a nil value
when looking at an emtpy CD-Rom Drive, but thats fine!
How would i go about comparing to see if both drives == nil!
Here the code:
tDrives = Drive.Enumerate();
for index in tDrives do
nDriveType = Drive.GetType(tDrives[index]);
if nDriveType == 5 then
tDriveInformation = Drive.GetInformation(tDrives[index]);
if tDriveInformation == nil and nil then -- it works with one (nil) but ejects
-- The other drive, i need them to
-- be both empty before ejecting!
Drive.Eject(tDrives[index]);
else
Dialog.Message("Disc in Drive", "A disc in 1 of the Drives", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
end
end
i thought the : nil and nil - would be good comparison, but it dosen't work.
As always, Thanks in advanced for looking!
mdxafx.
Roboblue
01-14-2007, 12:48 PM
I don't know how to get it using the AMS Drive actions (I'll have to look at it).
But, using Worms Drive Serial dll, this will eject any drive NOT having a disc in it. Just put the dll in the path shown in the code.
--- get the drives on the system
tblDrives = Drive.Enumerate();
--- walk the table to process each drive
for n, DriveLetter in tblDrives do
---Get the drive type
nType = Drive.GetType(DriveLetter)
--- if the type equals 5 (Fixed), get it's Label, and Serial
if nType == String.ToNumber(5) then
sSerial = DLL.CallFunction("AutoPlay\\Docs\\dll\\DriverSer.dll", "DriveSerialNumber", "\""..DriveLetter.."\"", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL)
sEject = ""..DriveLetter..""..sSerial..""
sFound = String.Find(sEject, "ERROR", 1, true);
if sFound ~= -1 then
Drive.Eject(sEject);
end
end
end
mdxafx
01-14-2007, 01:22 PM
Thats what my code does anyway, eject the drive which has
no disk in it.
what: Get.DriveInformation does is return a NIL value if there is
no disc in the drive.
what im trying to is see if both drive == NIL before ejecting them!
If only one drive == Nil there is a disc in one of the drive, therefore
do not eject any drive!
Thanks for the reply!
Hope someone can help me get the problem solved!
Buffman
01-15-2007, 01:06 AM
Hi mdxafx,
This is what I'd do in this situation. Let me know how this works out for you.
nFullDrive = 0; --Start out by declaring all CDROMS are empty
tDrives = Drive.Enumerate();
for index in tDrives do
nDriveType = Drive.GetType(tDrives[index]);
if nDriveType == 5 then
tDriveInformation = Drive.GetInformation(tDrives[index]);
if tDriveInformation ~= nil --Here look for a drive that has a disc in it
nFullDrives = nFullDrive+1;
end
end
end
if nFullDrive == 0 then
Drive.Eject(tDrives[index]);
else
Dialog.Message("Disc in Drive", "A disc in 1 of the Drives", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
I haven't tested the code, but the idea should work. It's late and I tend to make a lot of coding mistakes late at night. =)
Just for the hint, nil is not equal to another nil.
mdxafx
01-15-2007, 12:49 PM
Buffman: i corrected the errors and typo's in your code :
nFullDrive = 0; --Start out by declaring all CDROMS are empty
tDrives = Drive.Enumerate();
for index in tDrives do
nDriveType = Drive.GetType(tDrives[index]);
if nDriveType == 5 then
tDriveInformation = Drive.GetInformation(tDrives[index]);
if tDriveInformation ~= nil then -- (then) was missing!
nFullDrive = nFullDrive+1; -- was: nFullDrives = nFullDrive+1;
end
end
end
if nFullDrive == 0 then
Drive.Eject(tDrives[index]);
else
Dialog.Message("Disc in Drive", "A disc in 1 of the Drives", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
Correct me: -
but this code does not work because the three end statements closes
the argument therefore the : Drive.Eject(tDrives[index]);
returns: can't find string!
If you put:
if nFullDrive == 0 then
Drive.Eject(tDrives[index]);
else
Dialog.Message("Disc in Drive", "A disc in 1 of the Drives", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
before the three end statements you get
1 drive opens
1 stays closed (if you have 2 drive, 1 with a disc in it!).
Im going to look at this in more depth!
Any suggestion in the mean while of how this could be done would
be helpful!
Thanks to all!
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.