Passing arrays through functions

Discussion in 'ASP General' started by Henry, Sep 15, 2003.

  1. Henry

    Henry Guest

    Hi,

    I need to pass an array to a function, change it a little and return it to
    the main code. When i try it the webpage is displayed up until the function
    call. Nothing after that is displayed. When debugging in VS 6 it says: "An
    exception of type 'Error in Microsoft VBScript: Incompatible types' was not
    handled".

    'Main code
    '-----------------------------------------------------
    dim list(8)
    dim newlist(8)

    Randomize
    For counter = 0 To 4
    list(counter) = Int(Rnd * 21)
    Response.Write list(counter) & ", "
    Next

    Response.Write "<br>"
    newlist = listFunction(list)

    For counter = 0 To 4
    Response.Write newlist(counter) & ", "
    Next


    'function
    '-----------------------------------------------------
    Function listFunction(list)
    dim tmplist(8)

    Randomize
    For k = 0 To 4
    tmplist(k) = list(k)*2
    Next

    listFunction = tmplist
    End Function


    Also, when reloading the page i sometimes get the message 'A RPC (Remote
    Procedure Call) was not executed' (the message is translated from swedish by
    me). Does anyone know what i am doing wrong? Any help is welcome.

    /H
     
    Henry, Sep 15, 2003
    #1
    1. Advertising

  2. Henry

    Ray at Guest

    Try dimming newlist like so:

    'Main code
    '-----------------------------------------------------
    dim list(8)
    dim newlist

    Randomize
    ....

    Ray at work


    "Henry" <> wrote in message
    news:Mii9b.980$...
    > Hi,
    >
    > I need to pass an array to a function, change it a little and return it to
    > the main code. When i try it the webpage is displayed up until the

    function
    > call. Nothing after that is displayed. When debugging in VS 6 it says: "An
    > exception of type 'Error in Microsoft VBScript: Incompatible types' was

    not
    > handled".
    >
    > 'Main code
    > '-----------------------------------------------------
    > dim list(8)
    > dim newlist(8)
    >
    > Randomize
    > For counter = 0 To 4
    > list(counter) = Int(Rnd * 21)
    > Respons
     
    Ray at, Sep 15, 2003
    #2
    1. Advertising

  3. Henry

    Henry Guest

    Thanks Ray. That worked fine. Would you care to explain why that works and
    not my initial code?

    /Henrik

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> skrev i meddelandet
    news:...
    > Try dimming newlist like so:
    >
    > 'Main code
    > '-----------------------------------------------------
    > dim list(8)
    > dim newlist
    >
    > Randomize
    > ...
    >
    > Ray at work
    >
    >
    > "Henry" <> wrote in message
    > news:Mii9b.980$...
    > > Hi,
    > >
    > > I need to pass an array to a function, change it a little and return it

    to
    > > the main code. When i try it the webpage is displayed up until the

    > function
    > > call. Nothing after that is displayed. When debugging in VS 6 it says:

    "An
    > > exception of type 'Error in Microsoft VBScript: Incompatible types' was

    > not
    > > handled".
    > >
    > > 'Main code
    > > '-----------------------------------------------------
    > > dim list(8)
    > > dim newlist(8)
    > >
    > > Randomize
    > > For counter = 0 To 4
    > > list(counter) = Int(Rnd * 21)
    > > Respons

    >
    >
     
    Henry, Sep 15, 2003
    #3
  4. Henry

    Ray at Guest

    I think it's just one of the rules that once you declare a variable as an
    array, you cannot go and assign the whole array as something else, even if
    it is an array. By dimming it without the (), it is just a variant, and you
    can convert that variant into an array by "copying" the existing array.

    Ray at work

    "Henry" <> wrote in message
    news:07j9b.982$...
    > Thanks Ray. That worked fine. Would you care to explain why that works and
    > not my initial code?
    >
    > /Henrik
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> skrev i

    meddelandet
    > news:...
    > > Try dimming newlist like so:
    > >
    > > 'Main code
    > > '-----------------------------------------------------
    > > dim list(8)
    > > dim newlist
    > >
    > > Randomize
    > > ...
    > >
    > > Ray at work
    > >
    > >
    > > "Henry" <> wrote in message
    > > news:Mii9b.980$...
    > > > Hi,
    > > >
    > > > I need to pass an array to a function, change it a little and return

    it
    > to
    > > > the main code. When i try it the webpage is displayed up until the

    > > function
    > > > call. Nothing after that is displayed. When debugging in VS 6 it says:

    > "An
    > > > exception of type 'Error in Microsoft VBScript: Incompatible types'

    was
    > > not
    > > > handled".
    > > >
    > > > 'Main code
    > > > '-----------------------------------------------------
    > > > dim list(8)
    > > > dim newlist(8)
    > > >
    > > > Randomize
    > > > For counter = 0 To 4
    > > > list(counter) = Int(Rnd * 21)
    > > > Respons

    > >
    > >

    >
    >
     
    Ray at, Sep 15, 2003
    #4
    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. fivelitermustang

    Passing 2D Dynamic Arrays to Functions?

    fivelitermustang, May 14, 2004, in forum: C++
    Replies:
    6
    Views:
    2,618
    John Harrison
    May 14, 2004
  2. Replies:
    2
    Views:
    413
    Howard
    Jun 7, 2005
  3. kelvSYC

    Passing Arrays to Functions

    kelvSYC, Oct 11, 2003, in forum: C Programming
    Replies:
    8
    Views:
    410
    Peter Shaggy Haywood
    Oct 15, 2003
  4. James
    Replies:
    7
    Views:
    319
    James
    Nov 5, 2006
  5. Philipp
    Replies:
    21
    Views:
    1,130
    Philipp
    Jan 20, 2009
Loading...

Share This Page