|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Array questionI 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! On 8/12/2010 2:13 AM, Alexandros Peropulous wrote:
Show quoteHide quote > Hello! Have you seen this yet?> > 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! http://www.xtremevbtalk.com/archive/index.php/t-223190.html On 12/08/2010 10:13, Alexandros Peropulous wrote:
Show quoteHide quote > Hello! You can't do it via direct assignment.> > 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 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.) Dee Earley wrote:
Show quoteHide quote > On 12/08/2010 10:13, Alexandros Peropulous wrote: VB stores in column-major order. (So, the linear order of data in memor >> 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. 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 Or, a language that supports array slices (such as Fortran or Matlab)... :)> variants containing other arrays. sngTest = sngArr(1,:) % Matlab syntax; Fortran is very similar --
Show quote
Hide quote
"dpb" <n***@non.net> skrev i meddelandet Or use the easy way out.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 > > -- 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 Henning wrote:
Show quoteHide quote > "dpb" <n***@non.net> skrev i meddelandet Oh, indeed...take the obvious route. What's the fun in that?.... >> 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 .... 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. -- on 8/12/2010, dpb supposed :
Show quoteHide quote > Henning wrote: It's funny, but I can't think of any statically compiled language that >> "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. implements array slice functionality. It's seem to only be in the dynamic languages - Perl, Python, Ruby, etc..... -- Tom Shelton Tom Shelton wrote:
.... > It's funny, but I can't think of any statically compiled language that Fortran for at least one...requires F90+, but that's now the norm and is > implements array slice functionality. It's seem to only be in the > dynamic languages - Perl, Python, Ruby, etc..... 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) -- It happens that dpb formulated :
> Tom Shelton wrote: Ok... There's one. I'm not familar with fortran :)> ... > >> 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... -- Tom Shelton Tom Shelton wrote:
> It happens that dpb formulated : BASIC w/ Do...EndDo instead of For...Next>> 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 :) 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. -- Tom Shelton wrote:
> It happens that dpb formulated : Oh, I see somehow I lost the last of the posting after I inserted the >> 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 :) > examples of Fortran syntax... Add Ada and PL/I for others... Still don't see why it was never added into VB. -- dpb has brought this to us :
Show quoteHide quote > Tom Shelton wrote: Oh, yeah... forgot about ada. Been a few years since I touched that. >> 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... > 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 Tom Shelton wrote:
.... > It would be a nice feature. I use it all the time when I was doing Perl Why not use Fortran instead and get it for essentially free as well as > full time :) I think I'll have to implement a collection in C# that > does support it... concordant storage order? (smirk...) -- dpb submitted this idea :
> Tom Shelton wrote: Well... I suppose I could :)> ... > >> 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...) -- Tom Shelton dpb stellte die Frage :
> Tom Shelton wrote: With Fortran4 and Fortran7 you could have used Equivalence.> ... > >> 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, it's not the same but quite handy in some cases. Helmut. Helmut Meukel wrote:
Show quoteHide quote > dpb stellte die Frage : No, EQUIVALENCE is nothing like array slices except in the most >> 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. 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... :) -- |
|||||||||||||||||||||||