You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

efgee

Beginner

  • "efgee" started this thread

Posts: 9

Date of registration: Jun 30th 2009

  • Send private message

1

Wednesday, July 1st 2009, 1:34am

Dynamic Arrays in Structures possible?

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

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Wednesday, July 1st 2009, 10:46am

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

efgee

Beginner

  • "efgee" started this thread

Posts: 9

Date of registration: Jun 30th 2009

  • Send private message

3

Monday, July 6th 2009, 11:55pm

Thank you A1880.

That's a bummer that it doesn't work yet, but I have to put this "vb6 project conversion" on hold anyway because it seems that Jabaco doesn't have optional arguments in subs/functions either.

Maybe with the next version...

Thanks again
efgee

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

4

Tuesday, July 7th 2009, 12:07am

Quoted

That's a bummer that it doesn't work yet.
Thank you for the report. I'll fix this problem...

Quoted

it seems that Jabaco doesn't have optional arguments in subs/functions either.
Sample:

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

efgee

Beginner

  • "efgee" started this thread

Posts: 9

Date of registration: Jun 30th 2009

  • Send private message

5

Thursday, July 9th 2009, 10:56pm

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

This post has been edited 1 times, last edit by "efgee" (Jul 10th 2009, 2:10am)


efgee

Beginner

  • "efgee" started this thread

Posts: 9

Date of registration: Jun 30th 2009

  • Send private message

6

Friday, July 10th 2009, 2:09am

Regarding Dynamic arrays, such a thing:

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

Rate this thread
WoltLab Burning Board