I'm refactoring my code and trying to cut down on repetition. I've got this working code
<% If tree <> "" or (info <> "" and info <> "links" and info <> "privacy" and info <> "talks") Then %>
write stuff
<% End If %>
I put the info variables into an array
Dim info(3)
info(0) = "Talks"
info(1) = "Privacy"
info(2) = "Links"
I'm unclear as to iterate through the array
<% If tree <> "" or (info <> "" and **info <> arrayInfo** Then %>
write stuff
<% End If %>
Little help. Thanks.
Another technique is to create a string and instr().
InStr([start,]string1,string2[,compare]) If string2 is not found in string1 then InStr returns 0.
Note that the pipe separator is important at both the first and final positions of the string we search AND what we are seeking to match. Otherwise you get false-positives.
The technique is worthwhile with a few strings to test. The default compare mode is case sensitive but you can make it insensitive.
See http://www.w3schools.com/asp/func_instr.asp for details.
It is less purist than using a dictionary but worth being aware of.
Use a dictionary AND use a simpler conditional.
Although I agree with the above answer using the Instr function, there is an alternative. Your question is asking how to iterate through the array to test the values. Use a For..Next loop. Code example below.
Hope this helps.
You need a dictionary if you want to use one expression (.Exists) to obtain a fact (contained or not) about all elements of a collection. Look at:
output:
Here's the simplest way to iterate through the array since you asked specifically about that.