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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to cast array of strings to string

Status
Not open for further replies.

Stephon98caffe

Programmer
Feb 18, 2005
25
US
I keep getting the error Mismatch types

computersInOU is a array of computer names from an OU. I would just like to be able to put on computer name at time in the string strComputer and then send strComputer to the function IsConnectible.

For each x in computersInOU
strComputer = x
If strComputer <> "" Then
If IsConnectible(strComputer, "", "") Then
objOutputFiles.WriteLine "Reply received from " & strComputer
Else
objOutputFiles.WriteLine "Reply not received from " & strComputer
End If
End If

next
 
What error do you see?

Is computersInOU really an array or is it a collection object?

If it really is an array then try this syntax:
Code:
For x = LBound(computersInOU) to uBound(computersInOU)
   strComputer = computersInOU(x)
   .
   .
   .
Next
 
Stephon98caffe,

[1] If I recall the advice you received in the ou query thread, you receive as array object if there are objects found and only a string when there are none found.

[2] When you receive the return with undetermined dimension, you have to dim arrayvariable, rather than make the dynamic declaration dim arrayvariable().

Hence, I suspect you might have error at the level as described in [2] already. If not, you have to test if it is really an array:
[tt]
if isarray(computersInOU) then
'do what an array can do
else
'do what a string can do
end
[/tt]
regards - tsuji
 
Are you sure the variable computersInOU is an array?
The function Isarray(computersInOU) would return 'True' if it is...

So just try and see what is in it...
Code:
If IsArray(computersInOU) Then
	For x = LBound(computersInOU) to uBound(computersInOU)
		strComputer = computersInOU(x)
		WScript.Echo strComputer
	Next
Else
	WScript.Echo "Not an array: " & computersinOU
End if

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Damn! To slow... ;-)


--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top