I adapted the Get Free Space sample from over at
w3Schools. It works for me.
Here is a sample where I successfully polled the free space on my C: drive.
Option Explicit
'Called when the script is executed
Sub Object_OnScriptEnter
End Sub
Sub Object_OnLButtonUp(x, y, d)
If d Then Exit Sub
Dim fs, drive, n
Set fs = CreateObject("Scripting.FileSystemObject")
Set drive = fs.GetDrive("c:")
n = "Drive: " & drive & vbNewLine
n = n & "Available Space in bytes: " & drive.AvailableSpace
MsgBox n
Set fs = Nothing
Set drive = Nothing
End Sub
'Called when the script is terminated
Sub Object_OnScriptExit
End Sub
|
The line in your code,
Set MyDrivestate = drv.IsReady troubles me. IsReady does not return an object that would require the use of the Set keyword. It is just a boolean property.
I wish we could easily post formatted code, to make it easier to read. But I think the problem lies not with getting the GetDrive to work, but with some internal logic. It
looks like, from the script, you are setting a variable in the OnScriptEnter, and then checking the variable twice a second, which wouldn't achieve much.
Remember variable scopes, you must Dim outside of a sub or function if you want the variable to be accessible from all other subs and functions.
It appears that you are checking the drive status but once, then rechecking that initial check twice a second. You'll need to reperform the actual check on each firing.
Sub Object_OnTimer1134
Dim fs, drive
Set fs = CreateObject("Scripting.FileSystemObject")
Set drive = fs.GetDrive("c:")
If drive.IsReady Then
Object.State = "Ready"
Else
Object.State = "Not Ready"
End If
Set fs = Nothing
Set drive = Nothing
End Sub
|
ala
This othe w3Schools sample