functions returning arrays/duplicating arrays

Results 1 to 2 of 2

Thread: functions returning arrays/duplicating arrays

  1. #1
    Jeffrey Berthiaume Guest

    Default functions returning arrays/duplicating arrays

    I&#039;m trying to modify arrays either in subs or functions, and keep getting the error "Type mismatch" if I try to set one array equal to another, or "This array is fixed or temporarily locked" if I try to modify an array that I pass to a subroutine.<BR><BR>I&#039;ve done quite a bit of searching online, as well as in all of my VBScript and ASP books, and nobody seems to have really addressed passing parameters, or much in the way of array <BR>manipulation. For example: how can you return an array as a function value?<BR> <BR>(BTW: I found one place with code that did this the way I thought it should, but it resulted in a "Type mismatch" error on my machine...)<BR><BR>If anyone can point me to any resources, or has any suggestions, I would much appreciate them. Thanks!<BR><BR>-- j<BR><BR>Jeffrey Berthiaume<BR><BR><BR>&#060;%<BR>< BR> dim a (2), b (2)<BR><BR> a (0) = "foo"<BR> a (1) = "bar"<BR> a (2) = "baz"<BR><BR><BR> &#039; the following line blows up...whether it&#039;s in a function<BR> &#039; or not...<BR><BR> &#039; "Type mismatch"<BR> &#039;b = a<BR><BR> call copyarr (a, b)<BR><BR> &#039; this prints out all of the elements in array "b"<BR> for i = 0 to ubound (b)<BR> response.write b (i) & "<BR>" & vbCrLf<BR> next<BR><BR>&#039;---------------------------------------<BR><BR><BR> sub copyarr (arr1, byRef arr2)<BR> &#039; The following line generates the error:<BR> &#039; "This array is fixed or temporarily locked: &#039;arr2&#039;"<BR> redim arr2 (ubound (arr1))<BR> for i = 0 to ubound (arr1)<BR> arr2 (i) = arr1 (i)<BR> next<BR> end sub<BR><BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: functions returning arrays/duplicating arrays

    You can only ReDim dynamic arrays - ie arrays that have been declared like Dim myArray(), rather than Dim myArray(2).<BR><BR>Wouldn&#039;t it be easier to just return an new array from copyarr, rather than pass one in to be populated? eg:<BR><BR>Fuction copyarr(arr)<BR>Dim arrRet()<BR>ReDim arrRet(UBound(arr))<BR>For...<BR>Next<BR>copyarr = arrRet<BR>End Function<BR><BR>This is straight off the top of my head, but should work.<BR><BR>Dunc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts