Dynamic Arrays in Structures possible?
Hello,
have some VB6 code that looks like that:
As you can see there is a dynamic array inside a structure, this means that the "Bytes()" in the structure is actually a pointer to a dynamic array.
Now in this VB6 program both dynamic arrays are changed in different ways:
or:
Is this possible in Jabaco?
Thanks
efgee
have some VB6 code that looks like that:
|
|
Source code |
1 2 3 4 5 6 7 |
Type MYTABLE Name As String Bytes() As Byte 'pointer to dynamic array Value As Long End Type Public Hallodri() As MYTABLE 'dynamic array |
As you can see there is a dynamic array inside a structure, this means that the "Bytes()" in the structure is actually a pointer to a dynamic array.
Now in this VB6 program both dynamic arrays are changed in different ways:
|
|
Source code |
1 2 |
ReDim Preserve Hallodri(UBound(Hallodri) + 1) As MYTABLE ReDim Hallodri(UBound(Hallodri)).Bytes(0) |
or:
|
|
Source code |
1 |
ReDim Preserve Hallodri(2).Bytes(UBound(Hallodri(2).Bytes) + 1) As Byte |
Is this possible in Jabaco?
Thanks
efgee
Hi,
the following example works in VB6:
But I could not make it work in Jabaco. The "with" does not cope with array variables.
The direct redim in nested array structures does not seem to work either.
For my taste, redims should be used together with "with" to make clear which array level should be actually redimmed.
All in all, this is probably a good example for debugging Jabaco. But I would not recommend such high degree of dynamism anyhow.
You'll be paying a high price in terms of maintenance. Keep it simple!
Cheers!
A1880
the following example works in VB6:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
Option Explicit
Private Type MYTABLE
Name As String
Bytes() As Byte 'pointer to dynamic array
Value As Long
End Type
Private Hallodri() As MYTABLE 'dynamic array
Private s As String
Private Sub sh()
Dim lb As Integer
Dim t As String
lb = LBound(Hallodri)
t = "Hallodri(" & lb & " .. " & UBound(Hallodri) & ")." _
& "Bytes(" & LBound(Hallodri(lb).Bytes) & " .. " & UBound(Hallodri(lb).Bytes) & ")"
s = s & vbCrLf & t
Debug.Print t
End Sub
Private Sub Command1_Click()
Dim i As Integer
Dim ub As Integer
Debug.Print ""
s = ""
ReDim Hallodri(0 To 1)
For i = LBound(Hallodri) To UBound(Hallodri)
' ReDim Hallodri(i).Bytes(3 To 4)
With Hallodri(i)
ReDim .Bytes(3 To 4)
End With
Next i
sh
ub = UBound(Hallodri) + 1
ReDim Preserve Hallodri(ub) As MYTABLE
ReDim Hallodri(ub).Bytes(3 To 4)
For i = LBound(Hallodri) To UBound(Hallodri)
ub = UBound(Hallodri(i).Bytes) + 1
' ReDim Preserve Hallodri(i).Bytes(3 To ub) As Byte
With Hallodri(i)
ReDim Preserve .Bytes(3 To ub) As Byte
End With
Next i
sh
' ReDim Hallodri(LBound(Hallodri)).Bytes(3 To 3)
With Hallodri(LBound(Hallodri))
ReDim .Bytes(3 To 3)
End With
sh
ub = UBound(Hallodri(0).Bytes) + 1
' ReDim Preserve Hallodri(0).Bytes(3 To ub) As Byte
With Hallodri(0)
ReDim Preserve .Bytes(3 To ub) As Byte
End With
sh
MsgBox s, vbInformation, "Dynamic Arrays"
End Sub
|
But I could not make it work in Jabaco. The "with" does not cope with array variables.
The direct redim in nested array structures does not seem to work either.
For my taste, redims should be used together with "with" to make clear which array level should be actually redimmed.
All in all, this is probably a good example for debugging Jabaco. But I would not recommend such high degree of dynamism anyhow.
You'll be paying a high price in terms of maintenance. Keep it simple!
Cheers!
A1880
Thank you for the report. I'll fix this problem...
Quoted
That's a bummer that it doesn't work yet.
Sample:
Quoted
it seems that Jabaco doesn't have optional arguments in subs/functions either.
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 |
Public Sub test(Optional var1 As String = "test1", Optional var2 As String = "test2") MsgBox var1 & var2 End Sub Public Sub Command1_Click() Call test Call test("Replaced") 'Call test(, "Replaced") <<< not possible in java bytecode End Sub |
Hmm, ran another test - and you are right.
I had a sub with 4 parameters: STRING, LONG, ENUM, OPTIONAL LONG
and when I saw the error message talking about:
"Unexpected: Array!"
I knew this error message is wrong because there is no array used in this line.
So I expected the OPTIONAL parameter to be the one misguiding Jabaco.
But as it turns out it's the ENUM - if I change the 3rd parameter to a long then this line of code seems to run through.
Is there any chance to let ENUMS be a type of a parameter?
Thanks
efgee
I had a sub with 4 parameters: STRING, LONG, ENUM, OPTIONAL LONG
and when I saw the error message talking about:
"Unexpected: Array!"
I knew this error message is wrong because there is no array used in this line.
So I expected the OPTIONAL parameter to be the one misguiding Jabaco.
But as it turns out it's the ENUM - if I change the 3rd parameter to a long then this line of code seems to run through.
Is there any chance to let ENUMS be a type of a parameter?
Thanks
efgee
This post has been edited 1 times, last edit by "efgee" (Jul 10th 2009, 2:10am)
Regarding Dynamic arrays, such a thing:
doesn't compile yet... but hopefully soon.
bye
efgee
|
|
Source code |
1 2 3 4 5 6 7 8 9 |
Type MY_TYPE Name As String ChildArray() As Byte Characteristic As Long End Type Public ParentArray() As MY_TYPE ...... ReDim Preserve ParentArray(2).ChildArray(UBound(ParentArray(2).ChildArray) + 1) As Byte |
doesn't compile yet... but hopefully soon.
bye
efgee
Similar threads
-
General topics, questions and discussions »-
Considering the move to Jabaco
(Jun 30th 2009, 8:36pm)
-
General topics, questions and discussions »-
Structures in Jabaco
(May 23rd 2009, 12:57pm)
-
General topics, questions and discussions »-
ReDim Crash
(Mar 6th 2009, 1:11pm)
-
General topics, questions and discussions »-
Control Arrays
(Jan 16th 2009, 2:09am)
-
General topics, questions and discussions »-
Split
(Dec 17th 2008, 3:33pm)
