Forum Moderators: open
Here's the script
For i = 1 To Request.Form.Count
inputName = request.form.key(i)
inputVal = request.form.Item(i)
Set regx = New RegExp
'find fields in which no more than a set ceiling can be chosen but at least one must be chosen.
regx.Pattern = "_lvr\d$"
regx.IgnoreCase = True
reglvrVal = regx.Test(inputName)
limitValue = Trim(Right(inputName,1))
'if the input is an lvr, add the input name, value, and limitValue to an array
if reglvrVal = true then
if inputVal = "" then
displayName = regx.Replace(inputName, "")
missingElements = missingElements & "<strong>" & displayName & "</strong><br>"
else
dim iva
iva = Split(inputVal,",")
lvrCount = UBound(iva)
missingElements = missingElements & "<br><Br>lvrCount: " & lvrCount & " limitval: " & limitValue & "<br>"
missingElements = missingElements & "<br>limitValue: " & limitValue & " is numeric: " & isnumeric(limitValue) & "<br>"
missingElements = missingElements & "<Br>lvrcount: " & lvrCount & " is numeric: " & isnumeric(lvrCount) & "<br>"
missingElements = missingElements & "<Br>lvrcount (" & lvrCount & ") - limitValue (" & limitValue & ") equals " & (lvrCount - limitValue)
if (lvrCount > limitValue) then
missingElements = missingElements & begLimitErrorMsg & limitValue & displayName & "s</strong><br>"
missingElements = missingElements & "lvrcount: " & lvrCount & " IS GREATER THAN limitValue " & limitValue & "<br><br>"
else
missingElements = missingElements & "<br>lvrcount: " & lvrCount & " IS LESS THAN OR EQUAL TO limitValue " & limitValue & "<br><br>"
end if
end if
end if
Next
Here is the result of the script:
lvrCount: 5 limitval: 2
limitValue: 2 is numeric: True
lvrcount: 5 is numeric: True
lvrcount (5) - limitValue (2) equals 3
lvrcount: 5 IS LESS THAN OR EQUAL TO limitValue 2
At this point, I don't care if I DID do something stupid, I just want my misery to end. Help! Please! Where did I go wrong?
<added>I just tried setting lvrCount to 5 and limitValue to 2, overriding the values from the array length and input name. THEN, the comparison worked. So, is the "isnumeric" lying to me when it is saying that lvrCount and limitValue are both numbers? Even if it was lying, why would I be able to subtract the two variables, but not compare them?</added>
While my original problem is solved (can't get the correct comparison) I would really like to know why I couldn't compare in the first instance.
I think the problem was because your variable was being treated as type 'variant' (as all ASP variables truly are) and not 'integer' (numeric). So without explicitly setting the data type of the variable, you got the weird results. In the future, just always explicitly assign the data types of the variables you're trying use/compare.