Error when using an array of types

zurpa

New Member
Hi,

could someone help me with this :

I'm using a array of type :
Sub Globals
Dim Type(Dep, Arr, Fic1, Fic2, Tra) Depart (1)

Then, in a procedure, I'm reading the size of the array :
NbDepart = FileRead (c1)

I'm sizing the array :
Dim Depart (NbDepart)

But then I've got an error when trying :
Depart(0).Dep = 1

---
I've tried to put a fixed size on the array of type and it works.
I've tried to add 1 to NbDepart, to be sure it's concerted to an integer but it does not work.

Any idea ? Is this a bug ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
One dimension array-structures are actually two dimension arrays where the second rank value equals to the number of fields.
You must use the array syntax to resize the structure:
B4X:
Sub Globals
    Dim Type(Dep, Arr, Fic1, Fic2, Tra) Depart (0)
End Sub

Sub App_Start
    Dim Depart(NbDepart,5)
    Depart(0).dep = 13331
    Depart(1).Tra = 321
End Sub

Once you've declared a Global variable, you can't change its size :sign0163:
You can resize an array any number of times during a program (resizing an array will clear all its records).
 

Cableguy

Expert
Licensed User
Longtime User
Once you've declared a Global variable, you can't change its size :sign0163:

Not true...
I have used globals before, and have their initial value (set in the globals sub) altered in other subs....

I'm thinking more of a file related error...

B4X:
NbDepart = FileRead (c1)

Have you open the file for reading?
Are you sure you aren't getting an empty string?

EDIT: Erel beat me to the clock and as always he knows best...
 
Last edited:

taximania

Well-Known Member
Licensed User
Longtime User
Once you've declared a Global variable, you can't change its size :sign0163:

I meant a Global Array.
I stand corrected :signOops:

But: I'm even more confused now :sign0137:

B4X:
Dim Depart(NbDepart,5)
    Depart(0).dep = 13331

Doesn't that make an Array of NbDepart(5)

So shouldn't it be NbDepart(0).dep = 13331 etc :sign0137:
 

thecrowkaka

Member
Licensed User
Longtime User
I want to resize an array declared in global and yet be able to retain the data in the array. i.e. if I have an array a(5) and there is data in all the five elements. Now I want to make the array a(10), I need to have the data in the first five elements as it is and the next 5 elements would be clear. In vb6 we get this by using "Preserve" with Redim.

Please let me know if this is possible in B4PPC. Moreover, if not possible what could be the workaround to get this done?
 
Top