![]() |
Weird result with Arrays ---> please help
Hello all.
Simple concept here..i queryed my database (Access) , stored the resultes in a recordset, as usual Then i created a loop to put the contents of the recordset into an arry, but it only put one element in it. ..code below :
dim rArray(9)only the final element of the recordset is in the array did i set up the array right ? thanks |
you forgot to increment i :)
i++; After rArray(i)= recset(i); And, i don't think it's recset(i), ....... probably something like recset("mort"). But i may be way off here. |
Yuck... even when doing a for...next loop, you still have to increment "i"? That's a messy language indeed :P... I thought the incrementation of "i" was taken care of by the "next", as it was from my qb days (for i = 1 to 10 ... next i)
That aside... If you're only dimming the array to have 9 elts, yet you're looping through all of the record sets, wouldn't you go out-of-bounds eventually? It's unrelated, but funky stuff happens when you mess with memory. Then again, I don't know VB, so you can pretty much disregard everything I just wrote :P |
:
dim rArray(9) <-- Assumes that there are always 9 fieldsYou are copying the data from one array to another for each record and only returning the copied data after it has been overwritten several times. |
Damn .. i'm not giving advice on VB ever again :o
|
Why is it overiding the previous element in the rArray ? my logic was:
when i is 0 then rArray(0)=recset(0) when i is 1 then rArray(1)=recset(1) when i is 2then rArray(2)=recset(2) etc... how can i fix it so that i have an array with all the elements of the recordset??? |
Use a two-dimensional array:
:
Dim RecSet() |
Why would it not work with a 1d array?
The purpose for the array with the contents of the recordset is... i had 7 fields (entry) in the database of numbers (mortgage rates) and i have a form where i input the new ones, but to do an sql update statement you have to specify what the current data is....ie: UPDATE mort SET rate1 = ' " & newRate &" ' WHERE rate1= oldValue...> thats the problem ...the old value i have to query the database to get that old value but there's 7 of them so..i figured i'd use an array (see my code above) |
Quote:
:
| FieldA | FieldB | FieldC |
Thanks for all your help...but i think you misunderstood what i need...
I have to query my database for one type of information---> mortgage rates...no other info is needed to be in this array, as i need to use it in an update statement. If i want to update a field in the database (i will be updating all at once) i have to say change this value which you get from my form to this valu e (the one already in the database) .... thats where the problem is i wanted to do it all in 1 statement , thus i figured i needed an array with the data ...so...each field in my array has a mortgage rate in it how can i make a loop to copy the info from my recordset into an array ????? |
| All times are GMT -5. The time now is 9:33 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC