Simon Lomax
Simon Lomax

Reputation: 8982

VBscript anomalies

Why does the following work in VBScript (classic ASP)

Dim y: y = rs("file_description")
Dim x: x = (instr(y, "Internal Server Error") <> 0 or instr(y, "Server Unavailable") <> 0) AND instr(y, "RetryCount=9") = 0

But this does not work. It halts execution (without an error number or description!)

dim x: x = (instr(rs("file_description"), "Internal Server Error") <> 0 or instr(rs("file_description"), "Server Unavailable") <> 0) AND instr(rs("file_description"), "RetryCount=9") = 0

Seems strange that simply extracting the rs("file_description") expression into a variable causes the code to work.

I don't understand why.

Upvotes: 1

Views: 71

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38775

rs("file_description") can mean the field object or its default property .Value. VBScript picks one or another depending on the context. Because

y = rs("file_description")

does not use Set, y will contain the .Value. To make things clear for the second aproach, use

x = (instr(rs("file_description").Value, ...

Upvotes: 1

Related Questions