Solved Anybody know VB Scripting? Trying to fix an obsolete Gadget.

FuturDreamz

Spacemonaut
Guru
Local time
9:05 PM
Messages
1,660
Location
Lethbridge, AB
I've had this gadget That I really love, but it has a couple bugs. The problem is it's no longer supported by the developer. I had managed to fix one (simple formatting error), but the other one I located to being inside a VBScript file. Problem is, I know shit about Visual Basic. I'm pretty sure the problem is in a single line of code , and that would be easier to fix then rewriting the whole thing in JavaScript (especially since I most likely will be upgrading to Windows 8 soon)

The problem is with system uptime. it shows a big negative number, even though I restated earlier today.

Actually it seems to work fine on a computer running 32-bit Windows 7... But how do i fix this?

2ivgyf.png


\js\uptime.vbs:

Code:
Function GetUpdateInterval
    UpdateInterval = 1
    System.Gadget.Settings.write "UpdateInterval", UpdateInterval
    GetUpdateInterval = UpdateInterval * 1000
End Function
 
Sub uptime
 
    Set objLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objLocator.ConnectServer(MachineName, "root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
 
        For Each objOS in colOperatingSystems
 
            dtmBootup = objOS.LastBootUpTime
            dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
            dtmSystemUptimeSecs = DateDiff("s", dtmLastBootUpTime, Now)
 
            intSecsTotal     = dtmSystemUptimeSecs
            intDays           = Fix( intSecsTotal / 86400 )
            intSecsRemaining = ( intSecsTotal - ( intDays * 86400 ))
            intSecsTotal     = intSecsRemaining
            intHours         = Fix( intSecsTotal / 3600 )
            intSecsTotal    = ( intSecsTotal - ( intHours * 3600 ))
            intMinutes      = Fix( intSecsTotal / 60 )
 
            uptimeTxt.innerText = intDays & " days " & intHours & " hours " & intMinutes & " minutes"
            setTimeout "uptime()", GetUpdateInterval()
        Next
 
End Sub
 
 
Function WMIDateStringToDate(dtmBootup)
 
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
    Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
    & " " & Mid (dtmBootup, 9, 2) & ":" & _
    Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
 
End Function

Attached is the Gadget itself.
 

Attachments

Last edited by a moderator:

My Computer My Computer

At a glance

Windows 8 Pro (32-bit)1.83GHz Intel Core Duo2GB 667MHz DDR2 SDRAM (PC2-5300) (upgrade)ATI Radeon X1600 with 128MB GDDR3 memory
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Apple 17" iMac MA199LL (Early 2006)
OS
Windows 8 Pro (32-bit)
CPU
1.83GHz Intel Core Duo
Memory
2GB 667MHz DDR2 SDRAM (PC2-5300) (upgrade)
Graphics Card(s)
ATI Radeon X1600 with 128MB GDDR3 memory
Monitor(s) Displays
17-inch TFT active-matrix LCD, millions of colors
Screen Resolution
1440 x 900
Hard Drives
Hitachi 320GB HDT721032SLA360 7200RPM SATA II (upgrade)
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft Basic Optical Mouse v2.0
Internet Speed
4 Mbps
Antivirus
Microsoft Security Essentials
Browser
Google Chrome
Other Info
WEI:
Base Score: 3.9 Processor: 4.4 Memory 4.7
Graphics: 3.9 Gaming Graphics: 4.1 Primary HD: 5.9
  • Like
Reactions: JMH
It looks to me like the issue is not with the code but the internal functions it calls. For some reason they seem to return negative numbers...I have no idea why. Try putting a - in front of each occurrence of Fix. This should turn the negative value into a positive.
 

My Computer My Computer

At a glance

Win7-64Intel i7-3770S16GBnVidia GT630
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Custom built
OS
Win7-64
CPU
Intel i7-3770S
Motherboard
ASUS P8Z77-M
Memory
16GB
Graphics Card(s)
nVidia GT630
Sound Card
onboard
Monitor(s) Displays
dual
Screen Resolution
1920x1200 (primary) 1050x1680 (secondary)
Hard Drives
128GB SSD (boot)
64GB SSD (Temp/My Documents)
500GB (photos/videos)
1TB (rendered video, backups)
PSU
650W
Case
Thermaltake A30
Cooling
Thermaltake
Keyboard
Logitech Lighted
Mouse
Kensington Expert Mouse (trackball)
Internet Speed
FIOS 35/35
Antivirus
MS Security Essentials
Browser
Chrome (beta)
Actually I figured it's because the function receives a 64bit value, even when Sidebar is in 32bit mode. It's always off by 127 days, so I just changed line 19 to automatically add the difference, so it looks like this:
Code:
            intSecsTotal     = dtmSystemUptimeSecs + 10972800

Works fine now. Would need to be changed to work on a 32bit machine, but it's fine for my needs.
 

My Computer My Computer

At a glance

Windows 8 Pro (32-bit)1.83GHz Intel Core Duo2GB 667MHz DDR2 SDRAM (PC2-5300) (upgrade)ATI Radeon X1600 with 128MB GDDR3 memory
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Apple 17" iMac MA199LL (Early 2006)
OS
Windows 8 Pro (32-bit)
CPU
1.83GHz Intel Core Duo
Memory
2GB 667MHz DDR2 SDRAM (PC2-5300) (upgrade)
Graphics Card(s)
ATI Radeon X1600 with 128MB GDDR3 memory
Monitor(s) Displays
17-inch TFT active-matrix LCD, millions of colors
Screen Resolution
1440 x 900
Hard Drives
Hitachi 320GB HDT721032SLA360 7200RPM SATA II (upgrade)
Keyboard
Microsoft Wired Keyboard 600
Mouse
Microsoft Basic Optical Mouse v2.0
Internet Speed
4 Mbps
Antivirus
Microsoft Security Essentials
Browser
Google Chrome
Other Info
WEI:
Base Score: 3.9 Processor: 4.4 Memory 4.7
Graphics: 3.9 Gaming Graphics: 4.1 Primary HD: 5.9
Back
Top