Home All Groups Group Topic Archive Search About
Author
12 Aug 2010 9:13 AM
Alexandros Peropulous
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!

Author
12 Aug 2010 10:26 AM
Mike S
On 8/12/2010 2:13 AM, Alexandros Peropulous wrote:
Show quoteHide quote
> 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
Author
12 Aug 2010 10:54 AM
Dee Earley
On 12/08/2010 10:13, Alexandros Peropulous wrote:
Show quoteHide quote
> 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.ear***@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Author
12 Aug 2010 1:50 PM
dpb
Dee Earley wrote:
Show quoteHide quote
> 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

--
Author
12 Aug 2010 3:02 PM
Henning
Show quote Hide quote
"dpb" <n***@non.net> skrev i meddelandet
news:i40udv$v2e$1@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
Author
12 Aug 2010 3:17 PM
dpb
Henning wrote:
Show quoteHide quote
> "dpb" <n***@non.net> skrev i meddelandet
....

>> 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
....

Oh, indeed...take the obvious route.  What's the fun in that?

I was just being kinda' snarky... :)

It's been a pet peeve for years of mine that VB w/ all it's user
conveniences never implemented array slice notation.  It seems such an
obvious extension for a language intended for rapid development.

--
Author
12 Aug 2010 3:43 PM
Tom Shelton
on 8/12/2010, dpb supposed :
Show quoteHide quote
> Henning wrote:
>> "dpb" <n***@non.net> skrev i meddelandet
> ...
>
>>> 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
> ...
>
> Oh, indeed...take the obvious route.  What's the fun in that?
>
> I was just being kinda' snarky... :)
>
> It's been a pet peeve for years of mine that VB w/ all it's user conveniences
> never implemented array slice notation.  It seems such an obvious extension
> for a language intended for rapid development.

It's funny, but I can't think of any statically compiled language that
implements array slice functionality.  It's seem to only be in the
dynamic languages - Perl, Python, Ruby, etc.....

--
Tom Shelton
Author
12 Aug 2010 7:02 PM
dpb
Tom Shelton wrote:
....

> It's funny, but I can't think of any statically compiled language that
> implements array slice functionality.  It's seem to only be in the
> dynamic languages - Perl, Python, Ruby, etc.....

Fortran for at least one...requires F90+, but that's now the norm and is
20+ years old now...

Some examples; there are many other ways for usage as well...

Show quoteHide quote
> Array assignment is permitted when the array expression on the right
> has the same shape as the array variable on the left, or the expression
> on the right is a scalar.
> If the expression is a scalar, and the variable is an array, the
> scalar value is assigned to every element of the array.
> If the expression is an array, the variable must also be an array.
> The array element values of the expression are assigned (element by
> element) to corresponding elements of the array variable.
>
> A many-one array section is a vector-valued subscript that has two or
> more elements with the same value. In intrinsic assignment, the
> has the same shape as the array variable on the left, or the expression
> on the right is a scalar.

>
> Examples
>
> In the following example, X and Y are arrays of the same shape:
>
>   X = Y
>
> The corresponding elements of Y are assigned to those of X element by
> element; the first element of Y is assigned to the first element of X,
> and so forth. The processor can perform the element-by-element
> assignment in any order.
>
> The following example shows a scalar assigned to an array:
>
>   B(C+1:N, C) = 0
>
> This sets the elements B (C+1,C), B (C+2,C),...B (N,C) to zero.
>
> The following example causes the values of the elements of array A to
> be reversed:
>
>   REAL A(20)
>   ...
>   A(1:20) = A(20:1:-1)
>
....

> A vector subscript is a one-dimensional (rank one) array of integer
> values (within the declared bounds for the dimension) that selects a
> section of a whole (parent) array. The elements in the section do not
> have to be in order and the section can contain duplicate values.
>
> For example, A is a rank-two array of shape (4,6). B and C are
> rank-one arrays of shape (2) and (3), respectively, with the following
> values:
>   B = (/1,4/)           ! Syntax (/.../) denotes an array constructor
>   C = (/2,1,1/)         ! This constructor produces a many-one array section
>
> Array section A(3,B) consists of elements A(3,1) and A(3,4). Array
> section A(C,1) consists of elements A(2,1), A(1,1), and A(1,1). Array
> section A(B,C) consists of the following elements:
> A(1,2) A(1,1) A(1,1)
> A(4,2) A(4,1) A(4,1)
> An array section with a vector subscript that has two or more
> elements with the same value is called a many-one array section. For
> example:
>  REAL A(3, 3), B(4)
>  INTEGER K(4)
>  ! Vector K has repeated values
>  K = (/3, 1, 1, 2/)
>  ! Sets all elements of A to 5.0
>  A = 5.0
>  B = A(3, K)
>
> The array section A(3,K) consists of the elements:
>   A(3, 3) A(3, 1) A(3, 1) A(3, 2)

--
Author
12 Aug 2010 7:09 PM
Tom Shelton
It happens that dpb formulated :
> Tom Shelton wrote:
> ...
>
>> It's funny, but I can't think of any statically compiled language that
>> implements array slice functionality.  It's seem to only be in the dynamic
>> languages - Perl, Python, Ruby, etc.....
>
> Fortran for at least one...requires F90+, but that's now the norm and is 20+
> years old now...

Ok...  There's one.  I'm not familar with fortran :)

--
Tom Shelton
Author
12 Aug 2010 8:32 PM
dpb
Tom Shelton wrote:
> It happens that dpb formulated :
>> Tom Shelton wrote:
>> ...
>>
>>> It's funny, but I can't think of any statically compiled language
>>> that implements array slice functionality.  It's seem to only be in
>>> the dynamic languages - Perl, Python, Ruby, etc.....
>>
>> Fortran for at least one...requires F90+, but that's now the norm and
>> is 20+ years old now...
>
> Ok...  There's one.  I'm not familar with fortran :)

BASIC w/ Do...EndDo instead of For...Next

Syntax is very similar to BASIC; except for rather arcane features such
as Fortran pointers (which aren't needed for anything ordinary as are
for arrays, etc., in C or C-like languages but are handy for things like
linked lists, etc.), syntax would mostly be readily understandable by a
competent BASIC/VB user.

_Extremely_ useful w/ VB as the backend for compute-intensive stuff
since BASIC (and VB) inherited column-major array order from FORTRAN
(now officially Fortran).  The other way 'round sorta', of using VB as
the frontend for its GUI features is the real reason I ever got into VB
instead of Fortran entirely.

--
Author
12 Aug 2010 8:36 PM
dpb
Tom Shelton wrote:
> It happens that dpb formulated :
>> Tom Shelton wrote:
>> ...
>>
>>> It's funny, but I can't think of any statically compiled language
>>> that implements array slice functionality.  It's seem to only be in
>>> the dynamic languages - Perl, Python, Ruby, etc.....
>>
>> Fortran for at least one...requires F90+, but that's now the norm and
>> is 20+ years old now...
>
> Ok...  There's one.  I'm not familar with fortran :)
>

Oh, I see somehow I lost the last of the posting after I inserted the
examples of Fortran syntax...

Add Ada and PL/I for others...

Still don't see why it was never added into VB.

--
Author
12 Aug 2010 8:49 PM
Tom Shelton
dpb has brought this to us :
Show quoteHide quote
> Tom Shelton wrote:
>> It happens that dpb formulated :
>>> Tom Shelton wrote:
>>> ...
>>>
>>>> It's funny, but I can't think of any statically compiled language that
>>>> implements array slice functionality.  It's seem to only be in the
>>>> dynamic languages - Perl, Python, Ruby, etc.....
>>>
>>> Fortran for at least one...requires F90+, but that's now the norm and is
>>> 20+ years old now...
>>
>> Ok...  There's one.  I'm not familar with fortran :)
>>
>
> Oh, I see somehow I lost the last of the posting after I inserted the
> examples of Fortran syntax...
>
> Add Ada and PL/I for others...
>

Oh, yeah... forgot about ada.   Been a few years since I touched that. 
And even then, I was only playing :)  And, I fogot - but Pascal
supports it as well.  So, I take it back :)  There are some statically
compiled languages that do it... That wasn't to imply that they
couldn't by the way, just that I couldn't think of any of the top.

> Still don't see why it was never added into VB.

It would be a nice feature.  I use it all the time when I was doing
Perl full time :)  I think I'll have to implement a collection in C#
that does support it...

--
Tom Shelton
Author
12 Aug 2010 9:01 PM
dpb
Tom Shelton wrote:
....

> It would be a nice feature.  I use it all the time when I was doing Perl
> full time :)  I think I'll have to implement a collection in C# that
> does support it...

Why not use Fortran instead and get it for essentially free as well as
concordant storage order?

(smirk...)

--
Author
12 Aug 2010 9:41 PM
Tom Shelton
dpb submitted this idea :
> Tom Shelton wrote:
> ...
>
>> It would be a nice feature.  I use it all the time when I was doing Perl
>> full time :)  I think I'll have to implement a collection in C# that does
>> support it...
>
> Why not use Fortran instead and get it for essentially free as well as
> concordant storage order?
>
> (smirk...)

Well...  I suppose I could :)

--
Tom Shelton
Author
20 Aug 2010 3:46 PM
Helmut Meukel
dpb stellte die Frage :
> Tom Shelton wrote:
> ...
>
>> It's funny, but I can't think of any statically compiled language that
>> implements array slice functionality.  It's seem to only be in the dynamic
>> languages - Perl, Python, Ruby, etc.....
>
> Fortran for at least one...requires F90+, but that's now the norm and is 20+
> years old now...
>

With Fortran4 and Fortran7 you could have used Equivalence.
Ok, it's not the same but quite handy in some cases.

Helmut.
Author
20 Aug 2010 5:42 PM
dpb
Helmut Meukel wrote:
Show quoteHide quote
> dpb stellte die Frage :
>> Tom Shelton wrote:
>> ...
>>
>>> It's funny, but I can't think of any statically compiled language
>>> that implements array slice functionality.  It's seem to only be in
>>> the dynamic languages - Perl, Python, Ruby, etc.....
>>
>> Fortran for at least one...requires F90+, but that's now the norm and
>> is 20+ years old now...
>>
>
> With Fortran4 and Fortran7 you could have used Equivalence.
> Ok, it's not the same but quite handy in some cases.

No, EQUIVALENCE is nothing like array slices except in the most
rudimentary instance, perhaps, and it's still not much like it at all.

EQUIVALENCE is simply memory association and is static compilation-time
only.  Array slice is both dynamic and includes noncontiguous sections
amongst other differences.  One would have to manually recreate the
effect of an array slice programmatically using fixed array indices and
so on with EQUIVALENCE.

Uses of EQUIVALENCE are indeed handy but this isn't one of the ways in
which it would be... :)

--