Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

asp classic - Issue with if statement which should be true comes up as false

We recently migrated a very old site to a new server and are running into an odd issue. There is a simple if statement which should and did on old server read as true but it is not and not sure why. The statement is below. When I write out invflag it is equal to 1 which is what I would expect.

'does not trigger as true so iChk remains = ""
iChk = ""
if invflag = True then
    iChk = "checked"
end if

'Works as expected
iChk = ""
if invflag = "1" then
    iChk = "checked"
end if

'works as expected
iChk = ""
if invflag = 1 then
    iChk = "checked"
end if

I know we can simply fix this as you can see but we have these types of statements littered throughout the code and if there is something with the server or database we can set that would be ideal and thought I would check.

question from:https://stackoverflow.com/questions/65889253/issue-with-if-statement-which-should-be-true-comes-up-as-false

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Simply casting to CBool should do the trick for all cases:

If CBool(invflag) = True Then
    iChk = "checked"
End If

or better

If CBool(invflag) Then
    iChk = "checked"
End If

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...