declaring arrays

Naseoppobak

New Member
In classic ASP I declared the following array:<BR><BR>Dim arrZoomFactors(1,4)<BR>arrZoomFactors(0,0) = 1.1<BR>arrZoomFactors(1,0) = "0.1 times"<BR>arrZoomFactors(0,1) = 1.5<BR>arrZoomFactors(1,1) = "0.5 times"<BR>arrZoomFactors(0,2) = 2<BR>arrZoomFactors(1,2) = "2 times"<BR>arrZoomFactors(0,3) = 4<BR>arrZoomFactors(1,3) = "4 times"<BR>arrZoomFactors(0,4) = 8<BR>arrZoomFactors(1,4) = "8 times"<BR><BR>In my .aspx page I get the following error when I declare the same array: Declaration Expected (the error occurs on the first line after I declare the array)<BR><BR>I've tried changing the syntax to "Dim arrZoomFactors(1,4) as Array" or "Dim arrZoomFactors as Array" but nothing seems to work.<BR>I guess I have two questions. 1) Can you have an array that contains both strings and integers in vb.net? and 2) what is the proper way to declare this array?<BR><BR>Thanks,<BR><BR>Masmith<BR><BR><BR>Do you have Option Strict set? If so, you need to type all of your variables. If you want an array of Objects, you need to do:<BR><BR>Dim arrZoomFactors(1,4) as Object<BR><BR>If you want an array of Strings, do:<BR><BR>Dim arrZoomFactors(1,4) as String<BR><BR>etc. Also, you may want to look into the ArrayList class in the System.Collections namespace. It is like an array on steroids. :-)<BR>Nope, I didn't have Option Strict set, but if I did I'm not sure how I would dimension the array since it contains a mix of strings and integers.<BR>I just discovered that I can avoid the error by populating the array in the Page_Load subroutine, thus seperating the dimensioning from the populating. I'm still not clear why I can't do it the other way but at least its working!<BR><BR>Cheers
 
Back
Top