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.

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

1

Sunday, November 6th 2011, 6:39pm

Can not initialize Type variable (multidimensional array)

Hey there,

why does the following not work for a multidimensional array?

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Option Explicit

Private Type arr 
    a() As Long 
End Type


Public Sub Form_Load()
   Dim arr1 As arr
   'Redim arr1.a(0 To 4) 'works!!
   Redim arr1.a(0 To 4, 1 To 2)
   MsgBox "arr1.a " _
        & Lbound(arr1.a, 1) & " bis " & Ubound(arr1.a, 1) & ", " _
        & Lbound(arr1.a, 2) & " bis " & Ubound(arr1.a, 2)
   Unload Me
End Sub

'ERROR:
'java.lang.VerifyError: (class: Form1, method: Form_Load signature: ()V) Unable To pop operand Off an empty stack
'	at Module1.<clinit>(Module1.jsrc)



Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Sunday, November 6th 2011, 7:21pm

RE: Can not initialize Type variable (multidimensional array)

why does the following not work for a multidimensional array?

Don't have looked at your code now. But Multidemsinal Arrays are currently not supported in Jabaco.
I don't know why Manuel haven't used Java-Arrays for it. But at currently Arrays in Jabaco are based on VBArray:
http://code.google.com/p/jabacoframework…BA/VBArray.java
And VBArray and the current Jabaco-compiler are only supporting One-dimensional Arrays.

Jabaco Source

1
Dim A() As Integer

is exacly the same like

Jabaco Source

1
Dim A As VBArrayInteger


This is the reason, why you can not use of an array A the length with A.length and that you have to use Ubound(A) instead.

This is additional the readin why the main-Method in Jabaco looks like

Jabaco Source

1
Public Sub main(Byjava args() As String)


ByJava allows in Jabaco-SUBs and FUNCTIONs (and only at this position in the breaketts) to use the really Java String[] Array, instead on VBArrayString.

And if you creates an new Console Application, then the first text in Module1 is

Jabaco Source

1
2
3
4
5
6
Public Sub main(ByJava args() As String)
  Dim myArgs() As String
  myArgs = args
  ' [Your Source]

End Sub


args is a real Java String Array. But it can only be used in the SUB or FUNCTION header with ByJava. On any other place it can not be used.
So there exists myArgs which is a VBArrayString.
And "myArgs = args" casts the real Java Array to VBArrayString.

I don't like it, too.
And I don't see any advantage of this solution. I don't know in which case an Visual Basic Array differes from an Java Array, so that this solution is needed.
I have already discussed it here in the forum with A1880, who don't see any sense in VBArray, too.

Additional to use an own Class to simulate an Array (like Jabaco do it), instead of using Javas own one, it slows down the application.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

4

Sunday, November 6th 2011, 9:01pm

Hmmmm...thats sad...,

thanks for explaining in detail!
I am used to the VB restriction of Ubound and Lbound but reading your posts it seems like Java String Array provides features that would make life a lot easyer right now ;) .

So I guess I have to rewrite my VB6 chartplotting.bas a bit.
A x/y - price/Date plotting module.
Or maybe since I was populating the array from a database I might simply skip the array and use the resultSet instead and do the scale calculations on the fly or even in the SQL Statement. Fetching the data from an H2 table is pretty fast. I am not sure if this would slow down the plotting considerably?!


Thanks again,


Dani

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

5

Sunday, November 6th 2011, 10:26pm

Hey there again,

Actually on second thought Jabaco does support multidimensonal arrays!

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Option Explicit

Public Sub Form_Load()
Dim a() As Long
   Redim a(0 To 4, 1 To 2)
   MsgBox "a " _
    & Lbound(a, 1) & " bis " & Ubound(a, 1) & ", " _
    & Lbound(a, 2) & " bis " & Ubound(a, 2)
   Unload Me
End Sub

works fine and isn't that a multidimensional array?
It just does not work as part of my Type structure and I can not figure out why:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Option Explicit

Private Type arr 
    a() As Long 
End Type


Public Sub Form_Load()
   Dim arr1 As arr
   'Redim arr1.a(0 To 4) 'works!!
   Redim arr1.a(0 To 4, 1 To 2)
   MsgBox "arr1.a " _
        & Lbound(arr1.a, 1) & " bis " & Ubound(arr1.a, 1) & ", " _
        & Lbound(arr1.a, 2) & " bis " & Ubound(arr1.a, 2)
   Unload Me
End Sub

'ERROR:
'java.lang.VerifyError: (class: Form1, method: Form_Load signature: ()V) Unable To pop operand Off an empty stack
'at Module1.<clinit>(Module1.jsrc)


any thoughts?


Dani

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

6

Sunday, November 6th 2011, 11:47pm

the only people, who have best knowlege aboutr Jabaco is Manuel. But he don't answers questions in this forum since years. He only writes, when and if upcimming new versions of Jabaco come.



Actually on second thought Jabaco does support multidimensonal arrays!

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Option Explicit

Public Sub Form_Load()
Dim a() As Long
   Redim a(0 To 4, 1 To 2)
   MsgBox "a " _
    & Lbound(a, 1) & " bis " & Ubound(a, 1) & ", " _
    & Lbound(a, 2) & " bis " & Ubound(a, 2)
   Unload Me
End Sub

works fine and isn't that a multidimensional array?


Interesting. Thanks for that code.

Jabaco compiles it to;

Jabaco Source

1
2
3
4
5
6
7
8
public void Form_Load() {
   Object Err = null;
   VBArray a = new VBArray();
   a.setBound(1, 2, false);
   a.addDimension(0, 4, false);
   Interaction.MsgBox(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat("a ", String.valueOf(a.getLBound(1))), " bis "), String.valueOf(a.getUBound(1))), ", "), String.valueOf(a.getLBound(2))), " bis "), String.valueOf(a.getUBound(2))));
   Global.Unload((Form)this);
}







Quoted

It just does not work as part of my Type structure and I can not figure out why:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Option Explicit

Private Type arr 
    a() As Long 
End Type


Public Sub Form_Load()
   Dim arr1 As arr
   'Redim arr1.a(0 To 4) 'works!!
   Redim arr1.a(0 To 4, 1 To 2)
   MsgBox "arr1.a " _
        & Lbound(arr1.a, 1) & " bis " & Ubound(arr1.a, 1) & ", " _
        & Lbound(arr1.a, 2) & " bis " & Ubound(arr1.a, 2)
   Unload Me
End Sub

'ERROR:
'java.lang.VerifyError: (class: Form1, method: Form_Load signature: ()V) Unable To pop operand Off an empty stack
'at Module1.<clinit>(Module1.jsrc)


any thoughts?



I have not the time at the moment to look more exactly at it, but here is, what it compiles for:

Your Type is always itself compiled to an own class which looks like

Jabaco Source

1
2
3
4
5
6
7
import VBA.VBArray;
import VBA.VBArrayLong;
import VBA.VBTypeClass;

public class arr extends VBTypeClass {
   public VBArrayLong a = new VBArray();
}


Here if your outcommented is set (the one-dimensional array):

Jabaco Source

1
2
3
4
5
6
7
public void Form_Load() {
   Object Err = null;
   arr arr1 = new arr();
   arr1.a.setBound(0, 4, false);
   Interaction.MsgBox(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat(Strings.StrCat("arr1.a ", String.valueOf(arr1.a.getLBound(1))), " bis "), String.valueOf(arr1.a.getUBound(1))), ", "), String.valueOf(arr1.a.getLBound(2))),  " bis "), String.valueOf(arr1.a.getUBound(2))));
   Global.Unload((Form)Me);
}


And if it is compiled, when it is creates like you wrote it, all the decompilers can't decompile it.

JD-GUI only shows

Jabaco Source

1
2
3
4
5
public void Form_Load() {
    Throwable Err = null;
    arr arr1 = new arr();
    arr1.a.setBound(1, 2, false);
}



Possible a bug of the Jabaco compiler.

Ok, now here the code in Java-assembler deassembled with Javap:

The one-dimensional version (if your outcomment part ("Redim arr1.a(0 To 4)") is set and the other one "(Redim arr1.a(0 To 4, 1 To 2)") outcommented:

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
public void Form_Load();
  Code:
   0:   aconst_null
   1:   astore_1
   2:   new     #153; //class arr
   5:   dup
   6:   invokespecial   #154; //Method arr."<init>":()V
   9:   astore_3
   10:  aload_3
   11:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   14:  iconst_0
   15:  iconst_4
   16:  iconst_0
   17:  invokeinterface #164,  4; //InterfaceMethod VBA/IVBArray.setBound:(IIZ)V
   22:  ldc     #166; //String arr1.a 
   24:  aload_3
   25:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   28:  iconst_1
   29:  invokeinterface #170,  2; //InterfaceMethod VBA/IVBArray.getLBound:(I)I
   34:  invokestatic    #189; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   37:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   40:  ldc     #172; //String  bis 
   42:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   45:  aload_3
   46:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   49:  iconst_1
   50:  invokeinterface #175,  2; //InterfaceMethod VBA/IVBArray.getUBound:(I)I
   55:  invokestatic    #189; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   58:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   61:  ldc     #177; //String , 
   63:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   66:  aload_3
   67:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   70:  iconst_2
   71:  invokeinterface #170,  2; //InterfaceMethod VBA/IVBArray.getLBound:(I)I
   76:  invokestatic    #189; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   79:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   82:  ldc     #172; //String  bis 
   84:  invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   87:  aload_3
   88:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   91:  iconst_2
   92:  invokeinterface #175,  2; //InterfaceMethod VBA/IVBArray.getUBound:(I)I
   97:  invokestatic    #189; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   100: invokestatic    #183; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   103: invokestatic    #195; //Method VBA/Interaction.MsgBox:(Ljava/lang/String;)LVBA/VBMsgBoxResult;
   106: pop
   107: aload_0
   108: checkcast       #11; //class VB/Form
   111: invokestatic    #201; //Method VB/Global.Unload:(LVB/Form;)V
   114: nop
   115: return


And here the version, which don't run. The two-dimensional array:

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
public class Form1 extends VB.Form{
public void Form_Load();
  Code:
   0:   aconst_null
   1:   astore_1
   2:   new     #153; //class arr
   5:   dup
   6:   invokespecial   #154; //Method arr."<init>":()V
   9:   astore_3
   10:  aload_3
   11:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   14:  iconst_1
   15:  iconst_2
   16:  iconst_0
   17:  invokeinterface #164,  4; //InterfaceMethod VBA/IVBArray.setBound:(IIZ)V
   22:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   25:  iconst_0
   26:  iconst_4
   27:  iconst_0
   28:  invokeinterface #167,  4; //InterfaceMethod VBA/IVBArray.addDimension:(IIZ)V
   33:  ldc     #169; //String arr1.a 
   35:  aload_3
   36:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   39:  iconst_1
   40:  invokeinterface #173,  2; //InterfaceMethod VBA/IVBArray.getLBound:(I)I
   45:  invokestatic    #192; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   48:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   51:  ldc     #175; //String  bis 
   53:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   56:  aload_3
   57:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   60:  iconst_1
   61:  invokeinterface #178,  2; //InterfaceMethod VBA/IVBArray.getUBound:(I)I
   66:  invokestatic    #192; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   69:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   72:  ldc     #180; //String , 
   74:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   77:  aload_3
   78:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   81:  iconst_2
   82:  invokeinterface #173,  2; //InterfaceMethod VBA/IVBArray.getLBound:(I)I
   87:  invokestatic    #192; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   90:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   93:  ldc     #175; //String  bis 
   95:  invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   98:  aload_3
   99:  getfield        #158; //Field arr.a:LVBA/VBArrayLong;
   102: iconst_2
   103: invokeinterface #178,  2; //InterfaceMethod VBA/IVBArray.getUBound:(I)I
   108: invokestatic    #192; //Method java/lang/String.valueOf:(I)Ljava/lang/String;
   111: invokestatic    #186; //Method VBA/Strings.StrCat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
   114: invokestatic    #198; //Method VBA/Interaction.MsgBox:(Ljava/lang/String;)LVBA/VBMsgBoxResult;
   117: pop
   118: aload_0
   119: checkcast       #11; //class VB/Form
   122: invokestatic    #204; //Method VB/Global.Unload:(LVB/Form;)V
   125: nop
   126: return


Possible tomorrow or so I will look deeper in it. At the moment I have no time for it.


And thanks again, for the nice code, with an working two-diemensional array.

Greatings
theuserbl

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

7

Monday, November 7th 2011, 12:04am

Jabaco Source

1
2
3
'ERROR:
'java.lang.VerifyError: (class: Form1, method: Form_Load signature: ()V) Unable To pop operand Off an empty stack
'at Module1.<clinit>(Module1.jsrc)


Oh, and this sound very much as an compiler bug.
The JavaVM is a stack-vm. So there are numbers of variables and so, whoich are first "pushed" to a stack and later "poped" from it.
And the error is, that the stack is empty and the program says, to take something from it.
If a compiler works correct, it is impossible to create a program, which gives it out.

Greatings
theuserbl

Dani

Intermediate

  • "Dani" started this thread

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

8

Monday, November 7th 2011, 8:44am

Hey there thuserbl,

Quoted

At the moment I have no time for it.


I think you have been very 'gründlich' on this one allready!
Thanks for that.

I guess I can use the array outside the type structure then.


Dani

PS: I will post this in the Bugreport section. I am sure Manuel wil read it. A lot of people are very frustrated with him and I agree he should be a bit more present. The community would be much more active if he could drop a couple lines every week.
On the other hand he has given us a very stable and powerful tool with Jabaco. And he did do a fantastic job!

JasonS

Trainee

  • "JasonS" is male

Posts: 65

Date of registration: Feb 17th 2010

  • Send private message

9

Sunday, November 27th 2011, 10:05pm

Hello,

I have ran into this issue also... however, I have not had issues using variable arrays inside type structures.. as long as I have clearly defined its limits/min-max for the array... It appears you have done the same and it worked for you... For whatever reason it seems you cannot have an infinite or undefined array in Jabaco, but you could in VB6. It seems to work anywhere I have needed it to, as long as you define the arrays size up front...

I have not tried this, but I bet you could ReDim the variable array using another long or int variable holding the size value of the array (ubound and lbound).

Jabaco Source

1
Redim a(intAXLB To intAXUB, intAYLB To intAYUB)


Sincerely,
Jason

Rate this thread
WoltLab Burning Board