![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | syntax error in a class Hello, I'm trying to create a simple class that can display the current date using WMI functions. When I use the following code I get an error Syntax error in line strComputer = "." Why could this line cause a syntax error ? Here is the code : class current_date private strComputer public month public day public year strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime") For Each objItem in colItems month = objItem.Month day = objItem.Day year = objItem.Year Next end class '********************** dim test set test = new current_date wscript.echo test.month wscript.echo test.day wscript.echo test.year Thank you Heinz |
My System Specs![]() |
| | #2 (permalink) |
| | Re: syntax error in a class Heinz wrote: Quote: > > I'm trying to create a simple class that can display the current date > using WMI functions. > > When I use the following code I get an error > Syntax error in line strComputer = "." > > > Why could this line cause a syntax error ? > > Here is the code : > > class current_date > > private strComputer > public month > public day > public year > > strComputer = "." > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") > Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime") > > For Each objItem in colItems > > month = objItem.Month > day = objItem.Day > year = objItem.Year > > Next > > > end class > > '********************** > > dim test > set test = new current_date > > wscript.echo test.month > wscript.echo test.day > wscript.echo test.year > executable code outside of methods. They are not subroutines or functions in themselves, although they can define them within. This version worked for me, where I encapsulated the executable code in a Sub. Note I had to call the Sub to have the public properties assigned values: =============== class current_date public month public day public year Public Sub GetDate strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime") For Each objItem in colItems month = objItem.Month day = objItem.Day year = objItem.Year Next End Sub end class '********************** dim test set test = new current_date test.GetDate wscript.echo test.month wscript.echo test.day wscript.echo test.year -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #3 (permalink) |
| | Re: syntax error in a class "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> schrieb im Newsbeitrag news:u5BjMpVBKHA.1488@xxxxxx Quote: > Heinz wrote: > Quote: >> >> I'm trying to create a simple class that can display the current date >> using WMI functions. >> >> When I use the following code I get an error >> Syntax error in line strComputer = "." >> >> >> Why could this line cause a syntax error ? >> >> Here is the code : >> >> class current_date >> >> private strComputer >> public month >> public day >> public year >> >> strComputer = "." >> >> Set objWMIService = GetObject("winmgmts:\\" & strComputer & >> "\root\cimv2") >> Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime") >> >> For Each objItem in colItems >> >> month = objItem.Month >> day = objItem.Day >> year = objItem.Year >> >> Next >> >> >> end class >> >> '********************** >> >> dim test >> set test = new current_date >> >> wscript.echo test.month >> wscript.echo test.day >> wscript.echo test.year >> > VBScript classes can define properties and methods, but don't have > executable code outside of methods. They are not subroutines or functions > in > themselves, although they can define them within. This version worked for > me, where I encapsulated the executable code in a Sub. Note I had to call > the Sub to have the public properties assigned values: > =============== > class current_date > > public month > public day > public year > > Public Sub GetDate > strComputer = "." > > Set objWMIService = GetObject("winmgmts:\\" & strComputer & > "\root\cimv2") > Set colItems = objWMIService.ExecQuery("Select * From > Win32_LocalTime") > > For Each objItem in colItems > month = objItem.Month > day = objItem.Day > year = objItem.Year > Next > End Sub > > end class > > '********************** > > dim test > set test = new current_date > > test.GetDate > > wscript.echo test.month > wscript.echo test.day > wscript.echo test.year > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > great, thank you |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| syntax error in command prompt? | General Discussion | |||
| Help with syntax error in command prompt? | Gaming | |||
| Generic Interface syntax in VS 2005 using Old syntax | .NET General | |||
| Runtime Error: LIne:3 Syntax Error | Live Messenger | |||
| Vista System Restore Syntax error 0x800700B | Vista hardware & devices | |||