Array issue.....plz help
-
VB.net / sql myrow = DS.Tables("psrec").Rows(0) '1 record - 24 fields Dim myIntArray(24) As Integer For i = 0 To 23 myIntArray(i) = myrow(i) Next Array.Sort(myIntArray) maxunits = myIntArray(24) wat leaves me stumped is that since the array starts from 0, it should end at 23. However, the maxvalue can be found at myIntArray(24). when i print the array using the code, For i = 0 To 23 Console.WriteLine(myIntArray(i)) Next I always get 0 for myIntArray(0) for every record and the actual values are displayed from myIntArray(1). Therefore, one value is missed since the array prints till myIntArray(23). The last value is at myIntArray(24). Can you explain this to me... With Best Regards, Mayur
-
VB.net / sql myrow = DS.Tables("psrec").Rows(0) '1 record - 24 fields Dim myIntArray(24) As Integer For i = 0 To 23 myIntArray(i) = myrow(i) Next Array.Sort(myIntArray) maxunits = myIntArray(24) wat leaves me stumped is that since the array starts from 0, it should end at 23. However, the maxvalue can be found at myIntArray(24). when i print the array using the code, For i = 0 To 23 Console.WriteLine(myIntArray(i)) Next I always get 0 for myIntArray(0) for every record and the actual values are displayed from myIntArray(1). Therefore, one value is missed since the array prints till myIntArray(23). The last value is at myIntArray(24). Can you explain this to me... With Best Regards, Mayur
Since you have
Dim myIntArray(24) As Integer For i = 0 To 23 myIntArray(i) = myrow(i) Next
you never set the last value in the array, value myIntArray(24) That is the value which is missed? However, I would think the array should end at myIntArray(23) how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06 -
VB.net / sql myrow = DS.Tables("psrec").Rows(0) '1 record - 24 fields Dim myIntArray(24) As Integer For i = 0 To 23 myIntArray(i) = myrow(i) Next Array.Sort(myIntArray) maxunits = myIntArray(24) wat leaves me stumped is that since the array starts from 0, it should end at 23. However, the maxvalue can be found at myIntArray(24). when i print the array using the code, For i = 0 To 23 Console.WriteLine(myIntArray(i)) Next I always get 0 for myIntArray(0) for every record and the actual values are displayed from myIntArray(1). Therefore, one value is missed since the array prints till myIntArray(23). The last value is at myIntArray(24). Can you explain this to me... With Best Regards, Mayur
mayhem_rules wrote:
Dim myIntArray(24) As Integer
This is an array of 25 items. To declare an array of 24 items you use:
Dim myIntArray(23) As Integer
The number you supply when declaring an array is not the number of items, but the highest index to be used. I think that there are quite some VB programmers out there who constantly declares arrays that contain one too many items and never realise it, becase it seldom causes any errors. --- b { font-weight: normal; } -
mayhem_rules wrote:
Dim myIntArray(24) As Integer
This is an array of 25 items. To declare an array of 24 items you use:
Dim myIntArray(23) As Integer
The number you supply when declaring an array is not the number of items, but the highest index to be used. I think that there are quite some VB programmers out there who constantly declares arrays that contain one too many items and never realise it, becase it seldom causes any errors. --- b { font-weight: normal; }Thnk u very much... With Best Regards, Mayur