You are not logged in.

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

1

Friday, March 6th 2009, 1:11pm

ReDim Crash

Hi,
the following experiment shows how to define and re-define multi-dimensional arrays in Jabaco:

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
Public Sub Command1_Click()
   Dim arr(1 To 3, 2 To 4, 5 To 7) As Integer
   Dim b() As Integer 
   
   msgbox "arr " _
        & Lbound(arr, 1) & " .. " & Ubound(arr,1) & ", " _
        & Lbound(arr, 2) & " .. " & Ubound(arr, 2) & ", " _
        & Lbound(arr, 3) & " .. " & Ubound(arr, 3)

   Redim b(5 To 7, 2 To 4, 1 To 3)
   
   msgbox "b " _
        & Lbound(b, 1) & " .. " & Ubound(b, 1) & ", " _
        & Lbound(b, 2) & " .. " & Ubound(b, 2) & ", " _
        & Lbound(b, 3) & " .. " & Ubound(b, 3)

   Redim Preserve arr(5 To 7, 2 To 4, 1 To 3) 
   
   msgbox "arr p " _
        & Lbound(arr, 1) & " .. " & Ubound(arr,1) & ", " _
        & Lbound(arr, 2) & " .. " & Ubound(arr, 2) & ", " _
        & Lbound(arr, 3) & " .. " & Ubound(arr, 3)
        
   '  the following statement results in a crash
   Redim arr(5 To 7, 2 To 4, 1 To 3)
  '
  '  Jabaco compiles it to:
  '    arr.setBound(1, 3, false); arr.addDimension(2, 4, false); arr.addDimension(5, 7, false);
  '
   
   msgbox "arr " _
        & Lbound(arr, 1) & " .. " & Ubound(arr, 1) & ", " _
        & Lbound(arr, 2) & " .. " & Ubound(arr, 2) & ", " _
        & Lbound(arr, 3) & " .. " & Ubound(arr, 3)
   
End Sub


Any idea, why the non-preserving ReDim() of a defined array results in a runtime exception?

Cheers!

A1880

This post has been edited 2 times, last edit by "A1880" (Mar 6th 2009, 1:23pm)


OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Saturday, March 7th 2009, 9:50am

Hi A1880

in VB6 this does not compile much earlier in line 17 you get a errormessage:

"Error during comile: Array already dimensioned".

do you think that this should be possible in Jabaco whereas it is not possible in VB6?

btw:

in your second line:

Jabaco Source

1
Dim arr(1 To 3, 2 To 4, 5 To 7) As Integer

you define a fixedsize array in VB6

whereas with:

Jabaco Source

1
ReDim arr(1 To 3, 2 To 4, 5 To 7) As Integer

you can define and dimension a dynamical array in one line.

try it!

greetings

OlimilO

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

3

Saturday, March 7th 2009, 11:15am

Run-time exceptions vs. compile-time warnings

Hi,
you have a point there, I'm probably asking too much.

However, I would like to get warned at compile-time.
The Jabaco compiler should reduce the likelihood of run-time exceptions to a minimum.

Are you saying in your post, that an array which was declared via "ReDim" can be redim-ed dynamically?

The following line does not compile in my Jabaco IDE

Source code

1
2
 ReDim arrD(1 To 3, 2 To 4, 5 To 7) As Integer
 


Thanks for your analysis!

A1880

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Saturday, March 7th 2009, 12:14pm

hmm maybe we should first try to define how it should be expected from Jabaco.

what do you think?

should Jabaco react and do it the same way as VB6?

in VB6 this two sources are äquivalent to define and redim a dynamical array:

in one line:

Jabaco Source

1
ReDim arr(1 To 3, 2 To 4, 5 To 7) As Integer


in two lines:

Jabaco Source

1
2
Dim arr() As Integer
ReDim arr(1 To 3, 2 To 4, 5 To 7)


so the first one can be called as "syntactical sugar" :rolleyes:

making it possible in Jabaco maybe should be no problem we have to ask Manuel for that.

OlimilO

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

5

Saturday, March 7th 2009, 12:16pm

Quoted

However, I would like to get warned at compile-time.
The Jabaco compiler should reduce the likelihood of run-time exceptions to a minimum

of course i agree with you

OlimilO

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

6

Saturday, March 7th 2009, 12:44pm

Compliance to VB6

Hi,
as a rule of thumb, Jabaco should follow the syntax of VB6.
It should "swallow" most source codes which are considered valid VB6.
Where it make sense, extensions are nice.
Examples:
- I would like to have a standard function "length()" for array dimensions rather than fiddling around with UBound() and LBound()
- The standard properties of VB6 collections are fairly restricted. I do miss "contains()" for key-existance checks. A "sort()" would come handy as well.

Standard adherence has one big advantage: Developers can always look into the VB6 literature to get detailed information.

I would restrict "ReDim" to changes of array dimensions.
To me, it looks confusing to use ReDim as a Dim in the first place.

Greetings!

A1880

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

7

Saturday, March 7th 2009, 2:40pm

OK,

for Lists you have to look into java#util

Jabaco Source

1
2
3
4
5
6
7
8
Public Sub Command3_Click()
   Dim List As New java#util#ArrayList
   Dim i As Integer
   For i = 0 To 10
       List.add(i)
   Next
   MsgBox CStr(List.size)
End Sub


again to arrays:

what do you think about LBound?

imho:

the standard is: lbound is always 0 and therefor LBound is not longer used anymore.

greetings

OlimilO

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

8

Saturday, March 7th 2009, 2:56pm

contains

for "contains" the associative Hashtable is better:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Public Sub Command3_Click()
   Dim List As New java#util#ArrayList
   Dim i As Integer
   For i = 0 To 10
       List.add(i)
   Next
   MsgBox CStr(List.size)
   MsgBox "List.contains(5): " & List.contains(5)
   
   'for "contains" the associative Hashtable is better:
   Dim dic As New java#util#Hashtable
   dic.put("Apfel", "Apfel")
   dic.put("Birne", "Birne")
   dic.put("Melone", "Melone")
   dic.put("Kiwi", "Kiwi")
   dic.put("Kirsche", "Kirsche")
   If dic.containsKey("Melone") Then
       MsgBox dic.get("Melone")
   End If
End Sub


OlimilO

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

9

Saturday, March 7th 2009, 4:09pm

Thanks for your training material.
Well, I do know that plenty of frameworks and collection types are available in Java and somewhere in the internet.
However, I would like to have a clean and elegant programming environment within Jabaco. Therefore, *the* Collection should be just one class.
And this class should be so strong and versatile, that it can be used as the Swiss army knife for dynamic data structures.

Years ago I came across this library for linked lists in VB6.
Perhaps, this could influence the Jabaco collection. Reading Java sources with numerous collection types, I am always puzzled by their
varying specifics with regard to thread-safety, synchronization, direct element access, naming conventions, and so on.
There are good reasons to invent optimized types for special purposes. But one general type is much easier to apply and to maintain.

Usually, it is a good idea stick to LBound 0. But there are cases, when it makes sense to define other values.

Just my two cents ...

A1880

Rate this thread
WoltLab Burning Board