Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Problem with ConnectionString?

    I have got this script which works on my machine (Windows 7). But when I try it on my mates computer which runs Windows Vista I get the following error:

    Code:
    Disk not ready
    
    This means there is most likely a problem with the "ConnectionString" info that you specified.
    Here is the code:
    Code:
    <%
    dim fs
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    
    drive = "DEFGHIJKLMNO"
    display = ""
    checked = "checked"
    b = 0
    
    for i = 1 to len(drive)
      'Cycle through letters
      curChar = mid(drive,i,1)
      
      'Get the folder
      curDrive = curChar&":"
    
      'Check if drive exists
      if fs.driveexists(curDrive) = true then
      	b = b + 1
    	set driveObj = fs.GetDrive(curDrive)
    
    	'Get drive information
    	dtype = driveObj.DriveType 'Drive type
    	aspace = driveObj.AvailableSpace 'Available space
    	tspace = driveObj.TotalSize ' Total space
    	avspace = FormatPercent(aspace/tspace,0) 'Total space available
    	drivename = driveObj.VolumeName
    	
    	'Create option field  	  
    	optfield = 			"<div id="""&curChar&""" style=""display:"&display&";"">"
    	optfield = optfield & "<input type=""checkbox"" id=""device_"&curChar&""" name=""device_"&curChar
    	optfield = optfield & """ value="""&curChar&""" "&checked&"/>"
    	optfield = optfield & "<label for=""device_"&curChar&""">"&curChar&" - "&drivename&"<br />"
    	optfield = optfield & "Space Available: "&avspace&"</label>"
    	optfield = optfield & "</div>"
    	
    	response.write optfield
    	display = "none"
    	checked = ""
      end if
    next
    response.write "<input type=""hidden"" id=""devicecc"" value=""1/"&b&"""/>"
    response.write "<input type=""hidden"" id=""current"" value=""0"" />"
    %>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Got nothing whatsoever to do with "connection string".

    You aren't using a connection string, so how could it?

    I would *guess* that the problem is that your mate's machine has, perhaps, a USB card reader attached/builtin.

    Say that USB device is "H:".

    So it *DOES* exist, when you go to check it with the line:
    Code:
      if fs.driveexists(curDrive) = true then
    but then, when you try to get information FROM that device (such as AvailableSpace), because there is no card in the card reader indeed you get a "disk not ready" message.

    This is a problem with USB devices, in general: They exist, but they might not have any actual content.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-09-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Well at the time of testing it on my mates machine I had my external harddrive plugged in. He also has a built-in card reader which we tried.

    None worked, but they all work on my laptop. So are you saying its the machine?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    External hard drive PLUGGED IN should be fine.

    But card readers are iffy. It depends on the reader and the USB driver and and...

    For example, on this machine I'm currently working on, I have a 4-way card reader builtin. If I open up Windows Explorer and look at drives, if I do not have a card in the reader, then none of those 4 readers show as a drive. If I plug in a card, then NO MATTER WHICH reader I use, it always shows up as H:.

    On my wife's machine, she has an external 4-way card reader plugged into a USB port. And on that machine, no matter whether or not there is a card plugged in, *ALL FOUR* slots on that reader show up as *separate* drives, all the time, as G:, H:, I:, J:.

    So, yes, it depends entirely on the hardware and, no doubt, the drivers.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-10-2013)

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    What you could probably do is make a minor mod in your code:
    Code:
    for i = 1 to len(drive)
        'Cycle through letters
        curChar = mid(drive,i,1)
      
        'Get the folder
        curDrive = curChar & ":"
    
        'Check if drive exists
        If fs.driveexists(curDrive) Then ' no need for the = true ... just silly to use it
            set driveObj = fs.GetDrive(curDrive)
    
            'Get drive information... *MAYBE*
            On Error Resume Next
                dtype = driveObj.DriveType 'Drive type
                aspace = driveObj.AvailableSpace 'Available space
                tspace = driveObj.TotalSize ' Total space
            On Error GoTo 0
            If Err.Number = 0 Then
                ' only show drive info if we were able to actually get it!
                avspace = FormatPercent(aspace/tspace,0) 'Total space available
                drivename = driveObj.VolumeName
    
                b = b + 1 ' MOVE THIS TO HERE!!
         
                'Create option field            
                Response.Write "<div id="""&curChar&""" style=""display:"&display&";"">" _
                             & "<input type=""checkbox"" id=""device_"&curChar&""" name=""device_"&curChar _
                             & """ value="""&curChar&""" "&checked&"/>" _
                             & "<label for=""device_"&curChar&""">"&curChar&" - "&drivename&"<br />" _
                             & "Space Available: "&avspace&"</label></div>" & vbNewLine
                display = "none"
                checked = ""
            End If
        end if
    next
    Last edited by Old Pedant; 07-09-2013 at 11:26 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-10-2013)

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Thanks, I will have a look into that and test it soon.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Might need to move the setDrive call inside the ON ERROR. Dunno.

    That is:
    Code:
        'Check if drive exists
        If fs.driveexists(curDrive) Then 
            'Get drive information... *MAYBE*
            On Error Resume Next
                set driveObj = fs.GetDrive(curDrive)
                dtype = driveObj.DriveType 'Drive type
    ... etc. ...
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-10-2013)

  • #8
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Is there another way around this? Will JavaScript not work either, as I originally used JavaScript to find all of the drives.

    And i'm guessing I can still use ASP to detect a drive and just skip the getting the name ect...?

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    If you are using FileSystemObject, then whether you use JavaScript or VBScript won't matter. If you used some other technique with JavaScript, then go ahead: try it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-10-2013)

  • #10
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Just done some debugging on my mates machine and it does actually work. The following line was causing an error.

    Code:
    avspace = FormatPercent(aspace/tspace,0) 'Total space available

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,585
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Well, sure. If tspace is zero, then you get a "divide by zero" error.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-10-2013)

  • #12
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Old Pedant View Post
    Well, sure. If tspace is zero, then you get a "divide by zero" error.
    It shouldn't be 0. Plus it was working fine on my machine.. not too much of an issue anyway, that can be removed.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •