Array blowing up

Discussion in 'ASP General' started by Bill, Jul 31, 2003.

  1. Bill

    Bill Guest

    For some reason, when I try to run the following array, I'm getting an
    error:


    dim cat(0)

    cat(0)="0407"
    cat(1)="0102"

    'I will be adding more to this array, but just trying with two for
    starts.

    for counter = 0 to 1

    itno=cat(counter)

    'I get an error when it runs through this function

    Function rightvar(theVar,lengthNeeded)
    Dim sResult
    sResult=theVar
    if Len(theVar)< lengthNeeded then sResult= String(lengthNeeded -
    Len(theVar)," ")& theVar
    rightvar=sResult
    End Function


    Can someone help me understand why?

    Thanks.
     
    Bill, Jul 31, 2003
    #1
    1. Advertising

  2. You created an array to hold one item, but are filling it with two items,
    perhaps that's why the error. Try

    Dim Cat(1)

    The "1" represents the maximum, zero-based, index you can have in the array.
    In this case 1 means 0, 1 = 2 items.

    --
    Manohar Kamath
    Editor, .netBooks
    www.dotnetbooks.com


    "Bill" <> wrote in message
    news:...
    > For some reason, when I try to run the following array, I'm getting an
    > error:
    >
    >
    > dim cat(0)
    >
    > cat(0)="0407"
    > cat(1)="0102"
    >
    > 'I will be adding more to this array, but just trying with two for
    > starts.
    >
    > for counter = 0 to 1
    >
    > itno=cat(counter)
    >
    > 'I get an error when it runs through this function
    >
    > Function rightvar(theVar,lengthNeeded)
    > Dim sResult
    > sResult=theVar
    > if Len(theVar)< lengthNeeded then sResult= String(lengthNeeded -
    > Len(theVar)," ")& theVar
    > rightvar=sResult
    > End Function
    >
    >
    > Can someone help me understand why?
    >
    > Thanks.
     
    Manohar Kamath [MVP], Jul 31, 2003
    #2
    1. Advertising

  3. > Function rightvar(theVar,lengthNeeded)
    > Dim sResult
    > sResult=theVar
    > if Len(theVar)< lengthNeeded then sResult= String(lengthNeeded -
    > Len(theVar)," ")& theVar
    > rightvar=sResult
    > End Function


    That's the oddest indentation scheme I've yet seen.

    As for your errors, read up on Dim, ReDim and ReDim Preserve...
    http://msdn.microsoft.com/library/en-us/script56/html/vsstmdim.asp
    http://msdn.microsoft.com/library/en-us/script56/html/vsstmredim.asp

    ....and then tell us what kind of error you get when trying your rightvar
    function.

    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jul 31, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ashish
    Replies:
    1
    Views:
    569
    bruce barker
    Nov 17, 2003
  2. rao
    Replies:
    1
    Views:
    3,311
  3. asj
    Replies:
    138
    Views:
    2,496
    William Brogden
    Sep 1, 2003
  4. Replies:
    2
    Views:
    374
  5. John Nagle
    Replies:
    3
    Views:
    657
    Waldemar Osuch
    Nov 10, 2007
Loading...

Share This Page