![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Type mismatch: FormatNumber I want to determine the amount of free space on the hard drives in terms of Mega Bytes and format the output with digit grouping. My script keeps returning the error "Type mismatch: FormatNumber" and points to the line with the Echo. I can't figure out why the FormatNumber doesn't work. .... relevant code Const CONVERSION_FACTOR = 1048576 FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & _ MessageEnd & objLogicalDisk.DeviceID |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Type mismatch: FormatNumber "Larry" <Larry@xxxxxx> wrote in message news:B707B153-C9EF-4866-94E8-685F67EF4128@xxxxxx Quote: >I want to determine the amount of free space on the hard drives in terms of > Mega Bytes and format the output with digit grouping. My script keeps > returning the error "Type mismatch: FormatNumber" and points to the line > with > the Echo. I can't figure out why the FormatNumber doesn't work. > > ... relevant code > Const CONVERSION_FACTOR = 1048576 > FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR > WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & _ > MessageEnd & objLogicalDisk.DeviceID > "relevant code" omits several things which are relevant, e.g. your LogicalDisk object and the various string variables (?) in your echo statement. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Type mismatch: FormatNumber Sorry, I'm not familiar with code posting etiquette and I'm new to scripting. I left those things out because the script runs just fine until I try to format the number and the error points to the line with the FormatNumber. Here's the full code: Option Explicit Dim Computers, Computer Computers = Array(".") Dim MessageStart MessageStart = "There are " Dim MessageEnd MessageEnd = " MegaBytes of free disk space on " Dim colLogicalDisk, i, FreeMegaBytes, objLogicalDisk, objWMIService Const CONVERSION_FACTOR = 1048576 Const ONE_SECOND = 1000 Const ONE_MINUTE = 60000 Const ONE_HOUR = 3600000 Const WARNING_THRESHOLD = 10000 WScript.Echo "My computer name is " & Computers(0) For i = 1 To 1 For Each Computer In Computers Set objWMIService = GetObject("WinMgmtS://" & Computer) Set colLogicalDisk = objWMIService.InstancesOf("Win32_LogicalDisk") WScript.Echo "There are " & colLogicalDisk.Count & " logical drives on the computer " & Computer & "." For Each objLogicalDisk In colLogicalDisk FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & MessageEnd & objLogicalDisk.DeviceID If FreeMegaBytes < WARNING_THRESHOLD Then WScript.Echo vbTab & "The " & objLogicalDisk.DeviceID & " on " & Computer & " is low on disk space." Else WScript.Echo vbTab & "The " & objLogicalDisk.DeviceID & " on " & Computer & " has adequate disk space." End If Next WScript.Echo vbCr Next WScript.Sleep ONE_SECOND Next "Pegasus (MVP)" wrote: Quote: > > "Larry" <Larry@xxxxxx> wrote in message > news:B707B153-C9EF-4866-94E8-685F67EF4128@xxxxxx Quote: > >I want to determine the amount of free space on the hard drives in terms of > > Mega Bytes and format the output with digit grouping. My script keeps > > returning the error "Type mismatch: FormatNumber" and points to the line > > with > > the Echo. I can't figure out why the FormatNumber doesn't work. > > > > ... relevant code > > Const CONVERSION_FACTOR = 1048576 > > FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR > > WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & _ > > MessageEnd & objLogicalDisk.DeviceID > > > There is nothing wrong with the FormatNumber statement. Unfortunately your > "relevant code" omits several things which are relevant, e.g. your > LogicalDisk object and the various string variables (?) in your echo > statement. > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Type mismatch: FormatNumber The FreeSpace property is missing for CD drives (for example) that have no CD. Perhaps you can code similar to: FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR If IsNull(FreeMegaBytes) Then FreeMegaBytes = 0 End If -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "Larry" <Larry@xxxxxx> wrote in message news:93218821-0337-4C3A-8B62-11340AA8E009@xxxxxx Quote: > Sorry, I'm not familiar with code posting etiquette and I'm new to > scripting. > I left those things out because the script runs just fine until I try to > format the number and the error points to the line with the FormatNumber. > Here's the full code: > > Option Explicit > > Dim Computers, Computer > Computers = Array(".") > > Dim MessageStart > MessageStart = "There are " > > Dim MessageEnd > MessageEnd = " MegaBytes of free disk space on " > > Dim colLogicalDisk, i, FreeMegaBytes, objLogicalDisk, objWMIService > > Const CONVERSION_FACTOR = 1048576 > Const ONE_SECOND = 1000 > Const ONE_MINUTE = 60000 > Const ONE_HOUR = 3600000 > Const WARNING_THRESHOLD = 10000 > > WScript.Echo "My computer name is " & Computers(0) > For i = 1 To 1 > For Each Computer In Computers > Set objWMIService = GetObject("WinMgmtS://" & Computer) > Set colLogicalDisk = > objWMIService.InstancesOf("Win32_LogicalDisk") > WScript.Echo "There are " & colLogicalDisk.Count & " logical > drives on the computer " & Computer & "." > For Each objLogicalDisk In colLogicalDisk > FreeMegaBytes = objLogicalDisk.FreeSpace / > CONVERSION_FACTOR > WScript.Echo MessageStart & > FormatNumber(FreeMegaBytes,0,0,0-2) & MessageEnd & objLogicalDisk.DeviceID > If FreeMegaBytes < WARNING_THRESHOLD Then > WScript.Echo vbTab & "The " & > objLogicalDisk.DeviceID & " on " & Computer & " is low on disk space." > Else > WScript.Echo vbTab & "The " & objLogicalDisk.DeviceID & " on " > & > Computer & " has adequate disk space." > End If > Next > WScript.Echo vbCr > Next > WScript.Sleep ONE_SECOND > Next > > > "Pegasus (MVP)" wrote: > Quote: >> >> "Larry" <Larry@xxxxxx> wrote in message >> news:B707B153-C9EF-4866-94E8-685F67EF4128@xxxxxx Quote: >> >I want to determine the amount of free space on the hard drives in terms >> >of >> > Mega Bytes and format the output with digit grouping. My script keeps >> > returning the error "Type mismatch: FormatNumber" and points to the >> > line >> > with >> > the Echo. I can't figure out why the FormatNumber doesn't work. >> > >> > ... relevant code >> > Const CONVERSION_FACTOR = 1048576 >> > FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR >> > WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & _ >> > MessageEnd & objLogicalDisk.DeviceID >> > >> There is nothing wrong with the FormatNumber statement. Unfortunately >> your >> "relevant code" omits several things which are relevant, e.g. your >> LogicalDisk object and the various string variables (?) in your echo >> statement. >> >> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Type mismatch: FormatNumber I noticed that problem and was going to figure out how to deal with it later. I see what you're saying though. The value comes back as "Null" for those CD drives and FormatNumber doesn't know what to do that value so that's what's actually causing my problem. Awesome. Thanks for the help. "Richard Mueller [MVP]" wrote: Quote: > The FreeSpace property is missing for CD drives (for example) that have no > CD. Perhaps you can code similar to: > > FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR > If IsNull(FreeMegaBytes) Then > FreeMegaBytes = 0 > End If > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > "Larry" <Larry@xxxxxx> wrote in message > news:93218821-0337-4C3A-8B62-11340AA8E009@xxxxxx Quote: > > Sorry, I'm not familiar with code posting etiquette and I'm new to > > scripting. > > I left those things out because the script runs just fine until I try to > > format the number and the error points to the line with the FormatNumber. > > Here's the full code: > > > > Option Explicit > > > > Dim Computers, Computer > > Computers = Array(".") > > > > Dim MessageStart > > MessageStart = "There are " > > > > Dim MessageEnd > > MessageEnd = " MegaBytes of free disk space on " > > > > Dim colLogicalDisk, i, FreeMegaBytes, objLogicalDisk, objWMIService > > > > Const CONVERSION_FACTOR = 1048576 > > Const ONE_SECOND = 1000 > > Const ONE_MINUTE = 60000 > > Const ONE_HOUR = 3600000 > > Const WARNING_THRESHOLD = 10000 > > > > WScript.Echo "My computer name is " & Computers(0) > > For i = 1 To 1 > > For Each Computer In Computers > > Set objWMIService = GetObject("WinMgmtS://" & Computer) > > Set colLogicalDisk = > > objWMIService.InstancesOf("Win32_LogicalDisk") > > WScript.Echo "There are " & colLogicalDisk.Count & " logical > > drives on the computer " & Computer & "." > > For Each objLogicalDisk In colLogicalDisk > > FreeMegaBytes = objLogicalDisk.FreeSpace / > > CONVERSION_FACTOR > > WScript.Echo MessageStart & > > FormatNumber(FreeMegaBytes,0,0,0-2) & MessageEnd & objLogicalDisk.DeviceID > > If FreeMegaBytes < WARNING_THRESHOLD Then > > WScript.Echo vbTab & "The " & > > objLogicalDisk.DeviceID & " on " & Computer & " is low on disk space." > > Else > > WScript.Echo vbTab & "The " & objLogicalDisk.DeviceID & " on " > > & > > Computer & " has adequate disk space." > > End If > > Next > > WScript.Echo vbCr > > Next > > WScript.Sleep ONE_SECOND > > Next > > > > > > "Pegasus (MVP)" wrote: > > Quote: > >> > >> "Larry" <Larry@xxxxxx> wrote in message > >> news:B707B153-C9EF-4866-94E8-685F67EF4128@xxxxxx > >> >I want to determine the amount of free space on the hard drives in terms > >> >of > >> > Mega Bytes and format the output with digit grouping. My script keeps > >> > returning the error "Type mismatch: FormatNumber" and points to the > >> > line > >> > with > >> > the Echo. I can't figure out why the FormatNumber doesn't work. > >> > > >> > ... relevant code > >> > Const CONVERSION_FACTOR = 1048576 > >> > FreeMegaBytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR > >> > WScript.Echo MessageStart & FormatNumber(FreeMegaBytes,0,0,0-2) & _ > >> > MessageEnd & objLogicalDisk.DeviceID > >> > > >> > >> There is nothing wrong with the FormatNumber statement. Unfortunately > >> your > >> "relevant code" omits several things which are relevant, e.g. your > >> LogicalDisk object and the various string variables (?) in your echo > >> statement. > >> > >> > >> > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Type mismatch: FormatNumber "Larry" <Larry@xxxxxx> wrote in message news:93218821-0337-4C3A-8B62-11340AA8E009@xxxxxx Quote: > Sorry, I'm not familiar with code posting etiquette and I'm new to > scripting. > I left those things out because the script runs just fine until I try to > format the number and the error points to the line with the FormatNumber. > Here's the full code: enable respondents to see the cause of the problem. Some people post hundreds of lines of code, which is bad because respondents cannot really be expected to wade through the lot. You posted too little, leaving out the essential code segment as you saw later on. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Type mismatch:'alert' vbscript to compact access db | VB Script | |||
| Date Type mismatch in criteria expression | VB Script | |||
| Data type mismatch in criteria expression (with Request.form) | VB Script | |||
| Data type mismatch in criteria expression | VB Script | |||
| HTA: type mismatch (runtime) on sub call in OnChange | VB Script | |||