Hi Everyone,
I am new to VB . net, (used to be VB6) and have a problem copying a Uint16 array to another uint16 array.
This is the code:
Dim buffer(image_height, image_width) As System.UInt16 For a = 1 To image_height - 1Next Dim buffer2(image_width * image_height) As System.UInt16retcode = FLIGrabRow(device, buffer(a, 1), image_width)
Stat_bar.Panels(2).Text = Format((100 * a) / image_height, "0") & "%"
For a = 1 To image_height
For b = 1 To image_width
buffer2(a * b) = buffer(a, b)
Next NextEnd Code
So I have a 2D array named "buffer" that i need to copy to a 1D array, named "buffer2".
The code executes without error, but "buffer2" contains something very different then "buffer"
Can ayyone tell me what's wrong
Thanks alot,
Guy

copying a Uint16 array
Sniper167
increasing x -->
y 0 0 0 0
| 0 0 0 0
V 0 0 0 0
Then the corresponding indexes in a flattened version could be:
0 1 2 3
4 5 6 7
8 9 10 11
So an index is given by
(x position + no. of items in the rows above the current one))
(x Position + (no. of rows above * no. of items in 1 row))
(x Position + ( y Position * no. of items in 1 row))
Ok, the other problem is that in vb.net the arrays are 0 based. If you declare them like vb6 arrays then they will always have a spare slot:
Dim myArray(0) As Integer ' room for 1 item
Dim myArray(10) As Integer ' room for 11 items...
Dim myArray(width, height) As UInt16
' total size: (width + 1) * (height + 1)
So, it should be something like:
Dim buffer(image_height - 1, image_width - 1) As System.UInt16
For a = 0 To image_height - 1
Next
Dim buffer2((image_width * image_height) - 1) As System.UInt16
Next
Brian McKinney
Dim arr1 As UInt16(,)
Dim arr2 As UInt16()
ReDim arr1(10, 10) 'Some random size
'Loop through the array.
For i As Integer = 0 To 10
For n As Integer = 0 To 10
arr1(i, n) = (i * n) + (i + n) 'Set array position to some value
Next
Next
ReDim arr2(arr1.Length) 'Redim the new array to correct size
'Loop through the array aagin.
For i As Integer = 0 To 10
For n As Integer = 0 To 10
arr2((i * 10) + n) = arr1(i, n) 'Set the value of the new array. (Note, this will process in order of (0,0) (0,1) (0,2) and so on....
Next
Next
For i As Integer = 0 To arr2.GetUpperBound(0)
Debug.Print(arr2(i))
Next
ShurikAg
Thanks for the reply Dustin,
But when i try your code and compare the two array's, they are not the same ....
it misses one value at the end of each "row"
Guy
Warren13