Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

urgent Array passing to function problem

Status
Not open for further replies.

QLearnerNow

Programmer
Jul 1, 2003
22
AU
Hi guys,

I have an array

ColWidths = split("141|51|40|50|60|61|61",DELIM)

when I pass this to a function

CreateReport(aManagedFunds, ColWidths, True))

and try to access the individual elements of ColWidths

Function CreateReport(aData, ColWidths, HasBorder)
Dim Rows, Cols, Row, Col, BorderString, TableString,i,j

Rows = UBound(aData,1)
Cols = UBound(aData,2)


'Response.Write &quot;After&quot; & ColWidths(5) & &quot;<br>&quot;
'Response.Write &quot;Total no of Rows is :&quot; & Rows & &quot;<br>&quot;
'Response.Write &quot;Total no of Cols is :&quot; & Cols & &quot;<br>&quot;



for j = 0 to Cols

Response.Write &quot;the aData value is &quot; & ColWidths(j) & &quot;<br>&quot;
next

'Response.End

It works perfectly if Reponse.End is uncommented and prints out the ColWidths(j) value but if it is commented then
i get this error

Subscript out of range: 'j'

at point j=5

I find this totally weird. if anyone can help I will be very grateful

Regards,
QLearnerNow
 
I dont knw what you think but as a programming rule that somone onece told me and he's right
&quot;Computer never lies&quot;
So if you get Subscript out of range: 'j' you have to check your Ubound of the ColWidths array, as i see from your split example it should have 7 elements.
Also you check nr of elements from Cols = UBound(aData,2) with ColWidths wich they can be diferent.
Try to Response.Write both Cols and Ubound(ColWidths) and see if they ar same.

________
George, M
 
yeah MartinCurrie has the correct answer. it must be Cols-1 as the array will have one lemet lesser that its length as it starts from 0...

Known is handfull, Unknown is worldfull
 
Guys if you didnt saw it before it's not Cols-1 cuz
Cols = UBound(aData,2) returns the right index number.


________
George, M
 
shaddow is correct, UBound returns the Upper bound of the array, not the length. I once argued this for 30 minutes with a VB teacher because he believed (and was teaching) that arrays in VB could start with either 0 or 1 and have the number of elements you declare, so if you declared a(5) you could have indexes from 0-4 or 1-5 (in his class). This is incorrect.

When you declare an array in VB you are declaring the upper bound of the array, not the size. All arrays in VB are 0-based, and as far as I know there is no length or count method on the array in VBScript, only UBound.

So that portion should be ok, except for the fact that we are looping to the UBound of aData but accessing the array ColWidths. I would have to agree with shaddow (again) and suspect that the source of the problem is right there.

-Tarwn

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
now i am curious, i always thought ubound to be the length. what is meant by upperbound?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top