|
Post by garibaldi on Nov 16, 2016 16:34:23 GMT 1
Hi Forum,
Some questions about assigning variables :
1) How to assign array to member of other array (jagged array) ? The first assigning "a(2) = Array(1, 2)" is valid, but the second "a(2) = b()" raise an error
Dim a(1 To 2) As Variant, b(1 To 2) As Variant
a(1) = "Hello" a(2) = Array(1, 2) Print a(1), a(2)(0), a(2)(1)
b(1) = "X" b(2) = "Y" a(2) = b() '--> Syntax Error
2) What is wrong with this UDT assigning (the hash) ?
Type MyType v As Variant h As Hash Variant End Type
Dim x As MyType x.v = "Random string" x.h[1] = "One" '--> Syntax Error
3) Is the "New" keyword can only be used on declaration line (Dim) ?
This is valid in vba :
Dim collA As New Collection
collA.Add "Item 1", "One"
collA.Add new collection, "Two" '--> error but I got an error in GB32.
4) Can we use direct array copying like in vb :
Dim a(), b()
a() = b()
Thanks.
|
|
|
Post by dragonjim on Jan 3, 2017 0:37:00 GMT 1
Hi,
Apologies for taking so long to notice this post and reply...
Below are the answers to your questions to the best of my knowledge:
Although you can create variant arrays using the standard declarations as above, GB32 doesn't allow arrays declared in this fashion to be passed in the way you wish to do so. A work around to this problem is below:
Option Base 1 ' Starts arrays at 1 rather than 0 ' NOT ---> Dim a(1 To 2) As Variant, b(1 To 2) As Variant BUT Dim a As Variant = Array(0, 0), b As Variant = Array("", "")
a(1) = "Hello" a(2) = Array(1, 2) Print a(1), a(2)(1), a(2)(2)
b(1) = "X" b(2) = "Y" a(2) = b ' NOT b() Print a(1), a(2)(1), a(2)(2)
Sadly, a Hash can not be used in a Type structure as user-declared Types are not dynamic in GB32 and thus can not expand as you add values to your Hash array. It might be possible to assign your Hash array to a Variant and add your Variant to the Type, but I doubt the built in operands for Hash Arrays (Hash Add, etc) would work with such a construct.
Sadly, this is not valid in GB32. Try the following instead:
Dim collA As New Collection, collB As New Collection
collA.Add "Item 1", "One"
collA.Add collB, "Two"
The simple answer is yes, but not by using this syntax. The more complex answer is yes, by copying the data in the memory assigned to the source array to that of the destination array. A basic example is below:
Option Base 0 Dim a(10) As Int32, b(10) As Int32 // Each array has eleven elements, each sized to hold a 32-bit (4 byte) integer // Therefore, the data block of each array is 44 bytes long Local n As Int32 // Fill the a() array For n = 0 To 10 : a(n) = n : Next n // Copy the whole data block to the b() array MemCpy V:b(0), V:a(0), 44 // Display the identical values in the a() and b() arrays For n = 0 To 10 : Print a(n), b(n) : Next n
I hope these answers prove useful to you.
|
|
|
Post by garibaldi on Jan 3, 2017 12:27:02 GMT 1
Hi dragonjim,
Happy New Year and thank you for the respond. I am an Excel VBA programmer, and is trying to port some of my codes to a faster programming language (currently I am using VB6). In my codes, I use very very much dynamic array and hashing object (collection in this case) to achieve the result. But after learning from your post above, it is clear that GFA is not suitable for this purpose (although I am very impressed of its speed, what a pity).
Thank you so much for your help.
Regards
|
|
|
Post by dragonjim on Jan 3, 2017 12:57:30 GMT 1
Hi, I can understand your frustration with VBA (and VB6) speed wise compared to GB32 - however, the main disadvantage GB32 has is, although there have been bug fixes, there has been no major development in the structure of the language since the original team 'abandoned' it around the millennium. However, that said, the latest release of GB32 - you can get it from here - has been optimised specifically to work better with Excel, so there may be hope yet... In addition, there may be workarounds to GB32's lack of dynamic arrays - I use one, myself, for variable-length string storage within UDTs - so, if you can let me know what you are trying to achieve, I may be able to help. In addition, I have passed on your question about storing Hash arrays in UDTs and am waiting to see if anyone else has managed to make this work.
|
|
|
Post by dragonjim on Feb 25, 2017 13:16:21 GMT 1
OK. For the official answer (sorry for the delay): GFABasic was designed as a competitor for VB6, which suffered from speed and bloating issues, some of which were caused by the insertion of dynamic variables in locally declared types - hence, the strategic decision to used fixed length UDTs which did not carry the overheads, increased speeds but limited the language's flexibility. In the days of the newly released Pentium III and the slightly aged Pentium II with MMX, where average CPU rates were between 300 and 600 MHz on a single core processor, with many of us still bound to aging SRAM or the first incarnation of DDR, this was a sound idea and, even today in a world of considerably faster processors, memory and bus speeds, GFABasic is still noted for its speed; however, in that same world, the disadvantages of using dynamic structures have been reduced, and as can be seen from this post, are now accepted in return for the flexibility that they provide. For this reason, I have tried to compile a short lg32 library to add some of the dynamic features requested above and this can be found here.
|
|