Re: Help with Function Command
From: Steven Burn (pvt_at_noyb.com)
Date: 09/20/04
- Next message: Tom Lavedas: "Re: CopyFile Object Required Error"
- Previous message: Bob Barrows [MVP]: "Re: Help with Function Command"
- In reply to: Alisdair Philp: "Help with Function Command"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 20 Sep 2004 20:33:07 +0100
Move the Function code so it's BELOW the "Next" line
e.g.
Dim x
For x = 1 to 10
wscript.echo MyFunction(x)
Next
Function MyFunction(x)
MyFunction = x + 1
End Function
--
Regards
Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk
Keeping it FREE!
"Alisdair Philp" <ally.philp@dial.pipex.com> wrote in message
news:414f2a88$0$15886$cc9e4d1f@news.dial.pipex.com...
> I'm trying to write a script that connects to servers from a text file
read
> into a dictionary to get uptime from them. Uptime code is taken from
> Microsoft site, but when this runs I get a syntax error at the Function
> section. MS code works OK on a PC without the Dictionary code to read in a
> servers.txt file. Can anyone help on this?
>
> Thanks in Advance
>
> 'Read Server List Text File and Create Dictionary of Server Names
> Const ForReading = 1
> Set objDictionary = CreateObject("Scripting.Dictionary")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile ("c:\servers.txt", ForReading)
> i = 0
> Do Until objTextFile.AtEndOfStream
> strNextLine = objTextFile.Readline
> objDictionary.Add i, strNextLine
> i = i + 1
> Loop
> For Each objItem in objDictionary
> StrComputer = objDictionary.Item(objItem)
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colOperatingSystems = objWMIService.ExecQuery _
> ("Select * from Win32_OperatingSystem")
> For Each objOS in colOperatingSystems
> dtmBootup = objOS.LastBootUpTime
> dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
> dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
> Wscript.Echo dtmSystemUptime
>
> 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
> next
>
>
- Next message: Tom Lavedas: "Re: CopyFile Object Required Error"
- Previous message: Bob Barrows [MVP]: "Re: Help with Function Command"
- In reply to: Alisdair Philp: "Help with Function Command"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|