By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,011 Members | 2,968 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,011 IT Pros & Developers. It's quick & easy.

Passing arrays through functions

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try dimming newlist like so:

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

Randomize
....

Ray at work
"Henry" <he************@swipnet.se> wrote in message
news:Mi**************@nntpserver.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

Jul 19 '05 #2

P: n/a
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:OP**************@TK2MSFTNGP10.phx.gbl...
Try dimming newlist like so:

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

Randomize
...

Ray at work
"Henry" <he************@swipnet.se> wrote in message
news:Mi**************@nntpserver.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


Jul 19 '05 #3

P: n/a
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" <he************@swipnet.se> wrote in message
news:07**************@nntpserver.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:OP**************@TK2MSFTNGP10.phx.gbl...
Try dimming newlist like so:

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

Randomize
...

Ray at work
"Henry" <he************@swipnet.se> wrote in message
news:Mi**************@nntpserver.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



Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.