From: Alexandros Peropulous on
Hello!

I have documented my problem below.
Can anybody help? Could it be done by CopyMemory?

Private Sub Form_Load()

Dim sngArr() As Single
ReDim sngArr(1, 1)

sngArr(0, 0) = -5
sngArr(0, 1) = -7

sngArr(1, 0) = -8
sngArr(1, 1) = -12

'Looks like this:
' -5 -7
' -8 -12

Dim sngTest(1) As Single
sngTest() = sngArr(1) 'I want to put -8 -12 into my sngTest array,
but that's not working

End Sub

Thank you!
From: Mike S on
On 8/12/2010 2:13 AM, Alexandros Peropulous wrote:
> Hello!
>
> I have documented my problem below.
> Can anybody help? Could it be done by CopyMemory?
>
> Private Sub Form_Load()
>
> Dim sngArr() As Single
> ReDim sngArr(1, 1)
>
> sngArr(0, 0) = -5
> sngArr(0, 1) = -7
>
> sngArr(1, 0) = -8
> sngArr(1, 1) = -12
>
> 'Looks like this:
> ' -5 -7
> ' -8 -12
>
> Dim sngTest(1) As Single
> sngTest() = sngArr(1) 'I want to put -8 -12 into my sngTest array, but
> that's not working
>
> End Sub
>
> Thank you!

Have you seen this yet?

http://www.xtremevbtalk.com/archive/index.php/t-223190.html


From: Dee Earley on
On 12/08/2010 10:13, Alexandros Peropulous wrote:
> Hello!
>
> I have documented my problem below.
> Can anybody help? Could it be done by CopyMemory?
>
> Private Sub Form_Load()
>
> Dim sngArr() As Single
> ReDim sngArr(1, 1)
>
> sngArr(0, 0) = -5
> sngArr(0, 1) = -7
>
> sngArr(1, 0) = -8
> sngArr(1, 1) = -12
>
> 'Looks like this:
> ' -5 -7
> ' -8 -12
>
> Dim sngTest(1) As Single
> sngTest() = sngArr(1) 'I want to put -8 -12 into my sngTest array, but
> that's not working

You can't do it via direct assignment.

You MAY be able to do it with copymemory, but I can't remember which
orientation the array is in memory.

An alternative is to use an array of structures (Types) or an array of
variants containing other arrays.
This allows you to copy each main entry out of the main array as a whole.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
From: dpb on
Dee Earley wrote:
> On 12/08/2010 10:13, Alexandros Peropulous wrote:
>> Hello!
>>
>> I have documented my problem below.
>> Can anybody help? Could it be done by CopyMemory?
>>
>> Private Sub Form_Load()
>>
>> Dim sngArr() As Single
>> ReDim sngArr(1, 1)
>>
>> sngArr(0, 0) = -5
>> sngArr(0, 1) = -7
>>
>> sngArr(1, 0) = -8
>> sngArr(1, 1) = -12
>>
>> 'Looks like this:
>> ' -5 -7
>> ' -8 -12
>>
>> Dim sngTest(1) As Single
>> sngTest() = sngArr(1) 'I want to put -8 -12 into my sngTest array, but
>> that's not working
>
> You can't do it via direct assignment.
>
> You MAY be able to do it with copymemory, but I can't remember which
> orientation the array is in memory.

VB stores in column-major order. (So, the linear order of data in memor
for sngArr is [-5 -8 -7 -12])

Hence the copy isn't contiguous elements.

> An alternative is to use an array of structures (Types) or an array of
> variants containing other arrays.

Or, a language that supports array slices (such as Fortran or Matlab)... :)

sngTest = sngArr(1,:) % Matlab syntax; Fortran is very similar

--
From: Henning on

"dpb" <none(a)non.net> skrev i meddelandet
news:i40udv$v2e$1(a)news.eternal-september.org...
> Dee Earley wrote:
>> On 12/08/2010 10:13, Alexandros Peropulous wrote:
>>> Hello!
>>>
>>> I have documented my problem below.
>>> Can anybody help? Could it be done by CopyMemory?
>>>
>>> Private Sub Form_Load()
>>>
>>> Dim sngArr() As Single
>>> ReDim sngArr(1, 1)
>>>
>>> sngArr(0, 0) = -5
>>> sngArr(0, 1) = -7
>>>
>>> sngArr(1, 0) = -8
>>> sngArr(1, 1) = -12
>>>
>>> 'Looks like this:
>>> ' -5 -7
>>> ' -8 -12
>>>
>>> Dim sngTest(1) As Single
>>> sngTest() = sngArr(1) 'I want to put -8 -12 into my sngTest array, but
>>> that's not working
>>
>> You can't do it via direct assignment.
>>
>> You MAY be able to do it with copymemory, but I can't remember which
>> orientation the array is in memory.
>
> VB stores in column-major order. (So, the linear order of data in memor
> for sngArr is [-5 -8 -7 -12])
>
> Hence the copy isn't contiguous elements.
>
>> An alternative is to use an array of structures (Types) or an array of
>> variants containing other arrays.
>
> Or, a language that supports array slices (such as Fortran or Matlab)...
> :)
>
> sngTest = sngArr(1,:) % Matlab syntax; Fortran is very similar
>
> --

Or use the easy way out.
sngTest(0) = sngArr(1,0)
sngTest(1) = sngArr(1,1)

If lots of elements.
For i = 0 to NumElements
sngTest(i) = sngArr(1,i)
Next

/Henning