Reputation: 149
I am writing a VBS script and want to use the LEN command (as one of many) checks the hostname is set correctly. Hostname is ABCD12
ComputerName is returning the correct value and the hostname starts with ABCD so it proceeds - however LEN is returning a value of 0 (not 6) even though the hostname is 6 characters long. Why is this?
If left(ucase(ComputerName),4) = "ABCD" then
else
Wscript.quit(666)
End if
iLen=Len(ComputerName)
If ilen <> 6 Then
else
Wscript.quit(666)
End if
Upvotes: 0
Views: 38
Reputation: 10226
Your script works
Its just that you mess up with this If ilen <> 6 Then
it should be
If left(ucase(ComputerName),4) = "ABCD" then
else
Wscript.quit(666)
End if
iLen=Len(ComputerName)
If ilen = 6 Then
else
Wscript.quit(666)
End if
But you would better to code like this, it's way more intelligible
If left(ucase(ComputerName),4) <> "ABCD" then
Wscript.quit(666)
End if
If Len(ComputerName) <> 6 Then
Wscript.quit(666)
End if
or all in one
If (left(ucase(ComputerName),4) <> "ABCD") or (Len(ComputerName) <> 6) then
Wscript.quit(666)
End if
Upvotes: 1