Results 1 to 3 of 3

Thread: array issue

  1. #1
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default array issue

    Thanks in advance for your help!!!

    My issue is checking a array variable in a if statement to see if it empty.

    Like

    if pram(2) = "" then
    if empty redirect
    else
    not empty run code
    end if

    This is how my array is created

    strString=Request.ServerVariables("HTTP_X_ORIGINAL _URL")
    strArray = split(strString, "/")
    Redim pram(uBound(strArray))
    For i = 0 to uBound(strArray)
    pram(i) = strArray(i)
    Next


    I can get empty array by

    if uBound(strArray) = -1 then

    But I want to check the second item in the array if it's empty. The first item in the array will exist but the second item may not exist and then I need the to redirect the user accordingly.

  2. #2
    Join Date
    Apr 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You could try the isEmpty function, but I have heard mixed reviews on it's effectiveness.
    Code:
    If isEmpty(myArray)
       Response.Write "It's as empty as empty could be"
    Else
       Response.Write "This glass is half full"
    End If

  3. #3
    Join Date
    Apr 2017
    Location
    Kopenhagen
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    be careful of using the If strMyArray(1) = "" condition to determine if your array is empty.

    first, this is actually checking the second element in the array. remember that arrays are zero-based! so if you really wanted to do this, it would have to be written as If strMyArray(0) = ""

    and the second reason to be careful using this, is that an empty string in one element doesn't necessarily mean that all other elements are empty too!


    Sorry! Noticed this is an old thread!
    Last edited by jojohan; 04-20-2017 at 07:00 AM. Reason: added comment

Similar Threads

  1. Replies: 3
    Last Post: 03-01-2012, 03:42 PM
  2. Resolved Please help! For loop and Explode($array) issue
    By olliepop in forum PHP
    Replies: 1
    Last Post: 10-06-2010, 10:16 AM
  3. Array Issue
    By thesprucegoose in forum JavaScript
    Replies: 1
    Last Post: 03-12-2009, 09:55 PM
  4. Array issue with MySQL. I'm about to die
    By janniesekind in forum PHP
    Replies: 0
    Last Post: 02-04-2009, 10:50 PM
  5. Replies: 5
    Last Post: 08-20-2007, 03:02 AM

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
  •