Rounding Numbers
Numbers
Sunday, February 5, 2006 by jlaj1989 | Discussion: DesktopX
| 'Let's allocate the object globally, so we don't waste time allocating it on each call Dim objWMIService Dim szDrive Dim menu Dim res Dim fname Sub Object_OnScriptEnter 'If I wasn't so lame I'd write something that would go through the list of drives available and make sure only available drives are here but I'm too lazy for that. object.settimer 123, 2500 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") End Sub Sub Object_OnRButtonUp(x,y,Dragged) Set menu = DesktopX.CreatePopupMenu menu.AppendMenu 0, 1, "C:" menu.AppendMenu 0, 2, "D:" menu.AppendMenu 0, 3, "E:" menu.AppendMenu 0, 4, "F:" menu.AppendMenu 0, 5, "G:" menu.AppendMenu 0, 6, "H:" Dim result result = menu.TrackPopupMenu(&H00000004, System.CursorX, System.CursorY) executecontextmenu(result) End Sub Sub executecontextmenu(n) Select Case n Case 1 fname = "C:" Case 2 fname = "D:" Case 3 fname = "E:" Case 4 fname = "F:" Case 5 fname = "G:" Case 6 fname = "H:" End Select End Sub Sub Object_OnScriptExit Set objWMIService = nothing End Sub Sub Widget_OnPreferencesChange Object_OnTimer123 End Sub Sub Object_OnTimer123 Dim colItems Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where name = '" & fname & "'",,48) For Each objItem In colItems Object.text = fname &" " & objItem.FreeSpace / 1048576 & " MB" 'we just really need one result here, so we exit Exit Sub Next End Sub |
When it gives me a number it is something like H: 236.234375 MB how do i round the number so it will say something like H: 236.2 MB. Also it gives me the right number if it is in megabytes But if it is in gigabytes it will be in the thousands. is there anyway to change that to. It will say C: 9272.34765625 MB instead of C: 9.2 GB Thank You
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Sunday, February 5, 2006 7:26 PM
Dim objWMIService
Dim szDrive
Dim menu
Dim res
Dim fname
Sub Object_OnScriptEnter
'If I wasn't so lame I'd write something that would go through the list of drives available and make sure only available drives are here but I'm too lazy for that.
object.settimer 123, 2500
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
End Sub
Sub Object_OnRButtonUp(x,y,Dragged)
Set menu = DesktopX.CreatePopupMenu
menu.AppendMenu 0, 1, "C:"
menu.AppendMenu 0, 2, "D:"
menu.AppendMenu 0, 3, "E:"
menu.AppendMenu 0, 4, "F:"
menu.AppendMenu 0, 5, "G:"
menu.AppendMenu 0, 6, "H:"
Dim result
result = menu.TrackPopupMenu(&H00000004, System.CursorX, System.CursorY)
executecontextmenu(result)
End Sub
Sub executecontextmenu(n)
Select Case n
Case 1
fname = "C:"
Case 2
fname = "D:"
Case 3
fname = "E:"
Case 4
fname = "F:"
Case 5
fname = "G:"
Case 6
fname = "H:"
End Select
End Sub
Sub Object_OnScriptExit
Set objWMIService = nothing
End Sub
Sub Widget_OnPreferencesChange
Object_OnTimer123
End Sub
Sub Object_OnTimer123
Dim colItems
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where name = '" & fname & "'",,48)
For Each objItem In colItems
If objItem.FreeSpace / 1048576 < 1024 Then
Object.text = fname &" " & round((objItem.FreeSpace / 1048576),1) & " MB"
ElseIf objItem.FreeSpace / 1048576 > 1024 Then
Object.text = fname &" " & round((objItem.FreeSpace / 1024/1024/1024),1) & " GB"
'we just really need one result here, so we exit
End If
Exit Sub
Next
End Sub
'round