Professional Web Applications Themes

Passing arrays through functions - ASP

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) & ", ...

  1. #1

    Default Passing arrays through functions

    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 Guest

  2. #2

    Default Re: Passing arrays through functions

    Try dimming newlist like so:

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

    Randomize
    ....

    Ray at work


    "Henry" <henrik.pierrouswipnet.se> wrote in message
    news:Mii9b.980$d1.405nntpserver.swip.net...
    > 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 Guest

  3. #3

    Default Re: Passing arrays through functions

    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:OPNaBj4eDHA.2352TK2MSFTNGP10.phx.gbl...
    > Try dimming newlist like so:
    >
    > 'Main code
    > '-----------------------------------------------------
    > dim list(8)
    > dim newlist
    >
    > Randomize
    > ...
    >
    > Ray at work
    >
    >
    > "Henry" <henrik.pierrouswipnet.se> wrote in message
    > news:Mii9b.980$d1.405nntpserver.swip.net...
    > > 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 Guest

  4. #4

    Default Re: Passing arrays through functions

    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" <henrik.pierrouswipnet.se> wrote in message
    news:07j9b.982$d1.448nntpserver.swip.net...
    > 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:OPNaBj4eDHA.2352TK2MSFTNGP10.phx.gbl...
    > > Try dimming newlist like so:
    > >
    > > 'Main code
    > > '-----------------------------------------------------
    > > dim list(8)
    > > dim newlist
    > >
    > > Randomize
    > > ...
    > >
    > > Ray at work
    > >
    > >
    > > "Henry" <henrik.pierrouswipnet.se> wrote in message
    > > news:Mii9b.980$d1.405nntpserver.swip.net...
    > > > 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 Guest

Similar Threads

  1. Passing CF Arrays to javascript
    By dxsmith99 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 18th, 04:59 PM
  2. Passing arrays to functions
    By Eric Kincl in forum PHP Development
    Replies: 1
    Last Post: November 19th, 09:13 PM
  3. Passing Arrays
    By David P. Jessup in forum ASP
    Replies: 3
    Last Post: September 30th, 07:42 PM
  4. Replies: 4
    Last Post: July 24th, 12:30 AM
  5. Passing arrays to SP
    By Gary B in forum Microsoft SQL / MS SQL Server
    Replies: 3
    Last Post: July 10th, 05:49 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139