SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot seanlivo81's Avatar
    Join Date
    Jun 2002
    Location
    Bundaberg, Australia
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if a array contains "xxx"

    If I have a array like this:

    [VBS]
    Dim iArray
    iArray = Array("One","Two","Three","Four")
    [/VBS]

    How do I find out if the array contains one or more of them variable (eg. one, two, three or four)

  2. #2
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    found = false
    for i = 0 to ubound(iArray)
        if iArray(i) = value then
            found = true
        end if
    next
    EDIT: Thanks to Dave for pointing out my sloppy cut/paste mistake.
    Last edited by crowdozer; Sep 17, 2002 at 07:50.
    -- JIM BOLLA
    Wanna play Halo 2? My XBOX Live gamertag: crowdozer

  3. #3
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,266
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by crowdozer
    Code:
    found = false
    for i = 0 to ubound(iArray)
        if ubound(iArray) = value then
            found = true
        end if
    next
    Not quite. Code should be...
    Code:
    found = false
    for i = 0 to ubound(iArray)
        if iArray(i) = value then    ' This was the line in error...
            found = true
        end if
    next
    Or if you're only looking for the existance of one value (ie, don't care how many) then use....
    Code:
    found = false
    for i = 0 to ubound(iArray)
        if iArray(i) = value then    
            found = true
            exit for       ' prevents searching the whole array...
        end if
    next
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  4. #4
    SitePoint Zealot seanlivo81's Avatar
    Join Date
    Jun 2002
    Location
    Bundaberg, Australia
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I have got is a Select box that you can select Multiple values (Ctrl +Click)

    I want the variables in the database to highlight the options in the select box eg:

    Datebase field: "One, Three" ( I use the split to sperate the variables)

    The Page: The select box has one, two, three or four so when the page loads the database comes form the database it only selects One and Two from the select box.

    If you know what I mean.

  5. #5
    SitePoint Zealot seanlivo81's Avatar
    Join Date
    Jun 2002
    Location
    Bundaberg, Australia
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dave got it worked out here is the code to what I was tring to do if anyone else if is looking to do something like this.

    [VBS]
    <%
    Dim iVar, Secs

    Secs = Array("Gamer","Business","Security")
    iVar = "Security, Business"

    sArray = split(iVar, ",")
    %>
    <SELECT size=3 MULTIPLE>
    <%
    Sub Options
    for each thing in Secs
    Response.Write "<Option value=""" & thing & """"
    for each x in sArray
    x = trim(x)
    if x = thing then
    Response.Write " SELECTED"
    end if
    next
    Response.Write ">" & thing & vbCrlf
    next
    End Sub

    options
    %>
    </SELECT>
    [/VBS]


Bookmarks

Posting Permissions

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