Hi,
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