using redim & preserve in vb.net

psychedelik

New Member
I'm try to store data in a multi-dimensional array using vb.net. Well I'm try to save my current array info and add new info to it, but asp.net doesn't appear to support REDIM & PRESERVE inside subroutines. Does anyone have any info on this? I've posted my sample code below..TIA<BR><BR>sub save_array(sender as object,e as eventargs)<BR>dim myarray(5,5) as double<BR>dim newarray as new arraylist()<BR><BR> county = request.form("listing") 'This value is an index number. It will be 1 to 159 based off a listbox selection.<BR> salesTxt = request.form("sales1")<BR> sales2Txt = request.form("sales2")<BR> useTxt = request.form("use")<BR> foodTxt = request.form("food")<BR> exemptionsTxt = request.form("exemptions")<BR><BR>newarray.add(county) 'using a 1D array for easy looping<BR>newarray.add(salesTxt)<BR>newarray.add(sales2Txt)<BR>newarray.add(useTxt)<BR>newarray.add(foodTxt)<BR>newarray.add(exemptionsTxt)<BR><BR> <BR> for x = 0 to 5<BR> myarray(county,x) = newarray(x) 'storing my 1d array values in a 2d array based on county index number<BR> next<BR> <BR> for i = 0 to 5<BR> for x = 0 to 5<BR> response.write(myarray(i,x) & "<BR>")<BR> next<BR> next<BR>end subhttp://msdn.microsoft.com/library/en-us/vblr7/html/vastmredim.asp<BR><BR>The docs say it works. But since you don't show any code using it, nobody can tell what you might be doing wrong?<BR><BR><BR>Make myArray an ArrayList as well...It *should* work, either way.<BR><BR>And, besides, now you'd need an ArrayList with singly-dimensioned arrays as the members.<BR><BR>Well, no, you really shouldn't do that. Given what he is doing, it would make more sense to have an ArrayList of some kind of custom object, wouldn't it?<BR><BR>Hmmm....<BR><BR>Guess so. Im confused after studying his code now. Dont know exactly what he is trying to accomplish. I just figured if he needed to use redim he may as well just use another array list and just do an foreach iteration..What I'm trying to do is use a listbox to select a county and when they submit I store the county index number 1 to 159 along with the form values in an 2D array.<BR><BR>I use the arraylist to add my form values then loop through it only when I'm looping through the 2d array to store the values. The main problem I have, which is why I wanted to use redim & preserve, is that when a user hits submit the current 2d array loses it values then stores the new ones which doesn't do me any good.You DIMed the array inside the function/sub.<BR><BR>The array lives *ONLY* so long as the function/sub lives. When that function returns, the array is wiped from memory.<BR><BR>Each time you call the function/sub, you are creating a *new* array.<BR><BR>If you want it to last longer, you have to create the array in a scope that last longer than a function's lifetime (longer than a few microseconds).<BR><BR>
 
Back
Top