Error when using an array of types

Discussion in 'Questions (Windows Mobile)' started by zurpa, Oct 27, 2007.

  1. zurpa

    zurpa New Member


    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 ?
  2. taximania

    taximania Well-Known Member Licensed User

    Once you've declared a Global variable, you can't change its size :sign0163:
  3. Erel

    Erel Administrator Staff Member Licensed 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:
    Sub Globals
    Dim Type(Dep, Arr, Fic1, Fic2, Tra) Depart (0)
    End Sub

    Sub App_Start
    Dim Depart(NbDepart,5)
    0).dep = 13331
    1).Tra = 321
    End Sub
    You can resize an array any number of times during a program (resizing an array will clear all its records).
  4. Cableguy

    Cableguy Expert Licensed User

    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...

    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: Oct 27, 2007
  5. taximania

    taximania Well-Known Member Licensed User

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

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

    Dim Depart(NbDepart,5)
    0).dep = 13331
    Doesn't that make an Array of NbDepart(5)

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

    Erel Administrator Staff Member Licensed User

    NbDepart is an integer. We like to resize Depart which is an array of structures.
    As I wrote, an array of structures is actually a two dimensions array.
    Depart(0).Fic1 = 3 equals to Depart(0,2) = 3
    And when we need to resize Depart we write:
    Dim Depart(100,5) or Dim Depart(NbDepart,5) where 5 is the number of fields.
  7. thecrowkaka

    thecrowkaka Member Licensed 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?
  8. taximania

    taximania Well-Known Member Licensed User

    Copy the data into a temp array, resize the original one, copy the data back ?
  9. mjcoon

    mjcoon Well-Known Member Licensed User

    That's what I've been doing, where I thought that using a collection instead would be too much like hard work...

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice