How do I pass an array into a function?

Results 1 to 2 of 2

Thread: How do I pass an array into a function?

  1. #1
    Join Date
    Dec 1969

    Default How do I pass an array into a function?

    My function declaration is<BR>function setTabs(numTabs,selectID,lengthOfTab,txt())<BR><BR >and I want to call the function<BR><BR>dim a(3)<BR>a(0)="A"<BR>a(1)="B"<BR>a(2)="C"<BR>setTab s 4,3,100,a()<BR><BR>It returns a out of range error. How do I pass an array into the function?<BR>Also, is there a way to set a dynamic array? with "new array" and delete[] of some sort?<BR>Thanks in advance,<BR>Raymond

  2. #2
    Join Date
    Dec 1969

    Default RE: How do I pass an array into a function?

    you just pass it!<BR><BR>function checkArr(arr1) &#039;we&#039;ll just change the values<BR>for i = 0 to ubound(arr1)<BR>arr1(i) = 1<BR>next<BR>end function<BR><BR>dim myArr(2)<BR>myArr(0) = 2<BR>myArr(1) = 2<BR>myArr(2) = 2<BR>checkArr myArr<BR>&#039; now all the values should be 1<BR><BR><BR>in your code, there was some booboo&#039;s:<BR><BR>&#062; function setTabs(numTabs,selectID,lengthOfTab,txt())<BR><BR >&#062; dim a(3)<BR>&#062; a(0)="A"<BR>&#062; a(1)="B"<BR>&#062; a(2)="C"<BR>&#062; setTabs 4,3,100,a()<BR><BR>you set the array size to 3, but don&#039;t forget they start at 0. so your array really has 4 slots not 3 like you may have thought. when you call the function, just leave off the parenthesis after the array name and it should work fine.<BR><BR>if you want to declare a dynamic array just use the redim statement:<BR><BR>const iSize = 10<BR>dim strVar<BR><BR>redim strVar(iSize)<BR><BR>this gives you an array "strVar" with 11 slots, ubound of 10.<BR><BR>goodluck<BR>justin

Posting Permissions

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