Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Drive Display
#1
Hi,

I wrote this simple drive display function which is not that large.

It works in QB64 and uses library function GetDrivetype.

My question was:

  Id there a equivalent QB45/71 function to return drive type
  such as [cdrom] or [removable]??

Thanks, Erik.


Attached Files
.zip   DRIVEX.ZIP (Size: 151.81 KB / Downloads: 42)
.zip   DRIVEX2.ZIP (Size: 195.62 KB / Downloads: 28)
Reply
#2
A QBasic way...


Code: (Select All)
ON ERROR GOTO er1
FOR i = 1 TO 26
    drive$ = CHR$(i + 64)
    OPEN drive$ + ":\~.~" FOR INPUT AS #1: CLOSE #1
    IF found THEN
        IF found = 1 THEN PRINT drive$ ELSE PRINT drive$ + " not ready."
    END IF
NEXT
END

er1:
er% = ERR
SELECT CASE er%
    CASE 76
        ' Not found so do nothing.
        found = 0
    CASE 53
        found = 1
    CASE 68
        found = 2
END SELECT
RESUME NEXT

The "not ready" is going to be the optical drive if it does not contain media. Error 68 is drive not ready.

We can't use CHDIR as it will not differentiate a drive not ready, therefore it would not show the optical drive at all.

~.~ simply denotes a file name no one should have. It triggers the error 53, file not found, which we ignore. Error 76 is drive not found.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#3
This drive function works well in QB64 2.0.2 but in QB64 PE 3.4.1 throws an error which I cannot figure out:

C++ Compilation failed (Check .\internal\temp\compilelog.txt)


Nevermind:


  I had checked "Strip C++ symbols from executables." in Compiler settings in Alt-Options..


:? (i get worried when a Print "Hello world!" doesn't work...)
Reply
#4
This is an issue that has been discussed somewhat:

https://qb64phoenix.com/forum/showthread.php?tid=1183

Something was changed in MinGW which is preventing some programs from being created successfully. You could try to separately install v3.4.0 for now and try Pete's example again.
Reply
#5
Change the ~.~ to something less cryptic like "NoSuchFile.abc"

Pete
Reply
#6
Just downloaded 3.4.1 and the original code I posted compiled and worked just fine.

Pete
Reply
#7
(12-10-2022, 08:28 AM)Pete Wrote: Just downloaded 3.4.1 and the original code I posted compiled and worked just fine.

Pete

Thanks Pete..

  It was a problem with a compiler setting!

Erik.
Reply
#8
No problem. And now, thanks to your post, I've got V 3.4.1. Win-Win.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#9
Actually I was thinking more upon this:

Code: (Select All)
Declare Library
  Function GetDriveType& (d$)
End Declare

' declare library variables.
Dim Shared DriveType As String

' call drive type
For z = 1 To 26
   x = DRIVEEXISTS(z)
   If x = 0 Then
      Print Chr$(z + 64) + ": "; DriveType
   End If
Next
End

' check drive exists.
'  returns -1 if drive not detected.
Function DRIVEEXISTS (V)
  VarX$ = Chr$(V + 64) + ":\" + Chr$(0)
  VarX = GetDriveType(VarX$)
  DriveType = ""
  Select Case VarX
      Case 0
        DriveType = "[UNKNOWN]"
      Case 1
        DriveType = "[BADROOT]"
      Case 2
        DriveType = "[REMOVABLE]"
      Case 3
        DriveType = "[FIXED]"
      Case 4
        DriveType = "[REMOTE]"
      Case 5
        DriveType = "[CDROM]"
      Case 6
        DriveType = "[RAMDISK]"
  End Select
  If VarX > 1 Then
      DRIVEEXISTS = 0
  Else
      DRIVEEXISTS = -1
  End If
End Function
Reply
#10
(12-10-2022, 09:06 AM)eoredson Wrote: Actually I was thinking more upon this:
Why not have the function return a string instead? Needing a global string variable for the drive type is clunky. Could make it so it returns two values for the "not found" cases such as "[NONE][BADROOT]" or something else.
Reply




Users browsing this thread: 3 Guest(s)