Comparing an Array to a variable

Results 1 to 5 of 5

Thread: Comparing an Array to a variable

  1. #1
    Join Date
    Dec 1969
    Posts
    716

    Default Comparing an Array to a variable

    Hiyas all,<BR><BR>I am currently passing an array to an ASP which is a list of names eg: JohnMarkMatt - I have then used the Split function to seperate them into John, Mark, Matt. <BR><BR>Now what I need to do is compare the value of another variable eg: ExistingName to the array of names, whereby if a match is found the user would be forwarded to an error handler. I&#039ve had a lot of goes at this but just cannot seem to get it working =(<BR><BR>Thanks in advance for any help,<BR><BR>Justin

  2. #2
    Join Date
    Dec 1969
    Posts
    196

    Default RE: Comparing an Array to a variable

    You can use the InStr function<BR>InStr([start, ]string1, string2[, compare])<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    716

    Default RE: Comparing an Array to a variable

    Ahhh cool, erm i&#039m unfortunately still a bit of a newbie even though I seem to be progressing along nicely =) .. do you have any or know of any code examples of this?<BR><BR>Cheers,<BR><BR>Justin

  4. #4
    Nathen Grass Guest

    Default RE: Comparing an Array to a variable

    You can accomplish this by using a For..Next loop:<BR><BR>&#039arrNames is the array of names<BR>&#039strEName is the variable<BR><BR>Dim x, blnMatch<BR><BR>blnMatch = False &#039Default to no match<BR><BR>For x = 0 to Ubound(arrNames())<BR>&nbsp;&nbsp;&nbsp;If arrNames(x) = strEName Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blnMat ch = True<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit For<BR>&nbsp;&nbsp;&nbsp;End If<BR>Next<BR><BR>If blnMatch = True then<BR>&nbsp;&nbsp;&nbsp;&#039Execute error handler here<BR>Else<BR>&nbsp;&nbsp;&nbsp;&#039Execute code if there is no match here<BR>End If<BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    716

    Default RE: Comparing an Array to a variable

    Ahhhh, that looks like what I was looking for! - Cheers Nathen =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •