Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple variables in one Writeline statement?

Status
Not open for further replies.
Feb 11, 2005
153
US
I have a line such as this -

objFileOutput.WriteLine strDeviceName & "," & objSerialNumber & "," & objLoggedInUser & "

which will not write to a CSV format it gives me a syntax error. Though I can get a single variable to go by doing.
objFileOutput.WriteLine strDeviceName & ","

I also can get more of a second line in there by doing -
objFileOutput.WriteLine strDeviceName & ",Insert witty comment here."

How do I get the first line to show up as 1,2,3 so it shows up correctly in a csv?
 
objFileOutput.WriteLine strDeviceName & "," & objSerialNumber & "," & objLoggedInUser & "


you are trying to implicitly convert whatever

objSerialNumber and objLoggedInUser to strings

whilst most objects are kind enough to allow this i would not recommend on this type of reliance....i would go so far to suggest

CStr(objSerialNumber.PropertyX) & "," & CStr(objLoggedInUser.PropertyY)
 
>[tt]objFileOutput.WriteLine strDeviceName & "," & objSerialNumber & "," & objLoggedInUser [highlight]& "[/highlight][/tt]
Don't know what it is the highlighted part, it sure is syntax error. Take it out, I suppose!
 
Hrmmm I am missing something here - I understand some may not give out string values but shouldn't if its reporting out of WMI have a string value?

This sttempt isn't working even with a CStr.

I even went as far as this -

Set colLoggedInUser = objWMIService.ExecQuery _
("Select UserName from Win32_ComputerSystem")
For Each objLoggedInUser in colLoggedInUser
objFileOutput.Writeline CStr(objobjLoggedInUser.UserName)

I just cannot get this to display (or writeline) the value it sees in the - For Each objLoggedInUser in colLoggedInUser - line. I am correct in assuming it sees the value becaue it is processing the for line instead of going to the If colLoggedInUser.Count = 0 Then line I have above it in another section?

So far I have these WMI queries nested and I have msg boxes in each one just as a popup so I know this script works to know which machine had a serial number.

I can do msg boxes I can do a writeline of no variable but I can't seem to grab the variables from the queries.
 
i wasnt priv-ee to what objLoggedInUser was, other than your use of hungarian naming of your variable indictating that it is an object, hence the caution about implicitly relying on the class to show you something


For Each objLoggedInUser in colLoggedInUser
objFileOutput.Writeline CStr(objLoggedInUser.UserName)

you had objobjLoggedInUser so obj twice, do you ahve option explicit turned on?

if you can msgbox or wscript.echo something then you can write it to a log file

'this works therefore will have no problem writing to log file, looks like a typo which option explicit would ahve picked up for you

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colLoggedInUser = objWMIService.ExecQuery _
("Select UserName from Win32_ComputerSystem")
For Each objLoggedInUser in colLoggedInUser
Wscript.Echo CStr(objLoggedInUser.UserName)
Next

 
your use of objLoggedInUser and colLoggedInUSer could be misleading, depends how you look at it i guess,

i think you are really returning a collection of Win32_ComputerSystem objects but limiting the properties you return to jst the UserName...
 
Option explicit is not on.

And yes the typo was what messed it up I am so tired I missed it.

Now it is ouputting.

So in a writeline it should be -

writeline variable & "," & variable2 & ", "& variable 3 with no end quotes at all?

I just find this strange because aren't variables supposed to be called in " & variable & " form?

I keep getting syntax errors and unexpected end and things like that so I know its just how I have it written.

 
The strings are enclosed in quotes.

"," is a string as it is enclosed in quotes ... so if you have a trailing quote, all by its lonesom, it as an unterminated string which isn't allowed.



strebor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top