Android Question Array in Array Type problem

Tayfur

Well-Known Member
Licensed User
Longtime User
I cant upload values. do you have any idea?

B4X:
Private Mylist() As MyPage
   
    Type MyPage ( _
         Nick_name() As Nickname, _
         e_Mail() As email2, _
         User As String, _
         password As String)
   
    Type Nickname( _
       Name As String, _
       nick As String, _
       shortnick As String)
   
    Type email2( _
       adress As String, _
       server As String, _
       capacity As Int)

Sub Laods()
   
    Mylist(1).password="124"
    Mylist(1).user="user1"
        Mylist(1).Nick_name(1).Name="nick1"
        Mylist(1).Nick_name(1).nick="nick1_11"
        Mylist(1).Nick_name(1).shortnick="n1"
        Mylist(1).Nick_name(2).Name="nick2"
        Mylist(1).Nick_name(2).nick="nick1_22"
        Mylist(1).Nick_name(2).shortnick="n2"
       
        Mylist(1).e_Mail(1).adress="[email protected]"
        Mylist(1).e_Mail(1).capacity=12
        Mylist(1).e_Mail(1).server="gmail.com"
        Mylist(1).e_Mail(2).adress="ffabs@yahıı.xom"
        Mylist(1).e_Mail(2).capacity=12
        Mylist(1).e_Mail(2).server="yahoo.com"
       
    Mylist(2).password="45687"
    Mylist(2).user="user2"
        Mylist(2).Nick_name(1).Name="nick3"
        Mylist(2).Nick_name(1).nick="nick1_33"
        Mylist(2).Nick_name(1).shortnick="n3"
        Mylist(2).Nick_name(2).Name="nick4"
        Mylist(2).Nick_name(2).nick="nick1_44"
        Mylist(2).Nick_name(2).shortnick="n4"
       
        Mylist(2).e_Mail(1).adress="[email protected]"
        Mylist(2).e_Mail(1).capacity=1222
        Mylist(2).e_Mail(1).server="gmail.com"
        Mylist(2).e_Mail(2).adress="qwwqw@yahıı.xom"
        Mylist(2).e_Mail(2).capacity=1299
        Mylist(2).e_Mail(2).server="yahoo.com"
   
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
I cant upload values
I can not see any code which uploads this type-array!?!? I also can not see where you define the size of the used arrays. Starting at MyList...
I also did not see any error message you have posted if you get any error.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
I can not see any code which uploads this type-array!?!? I also can not see where you define the size of the used arrays. Starting at MyList...
I also did not see any error message you have posted if you get any error.
Erorr:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=1

how can add in it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
how can add in it.
Read the BEGINNERSGUIDE

10.3.4 Type variables
A Type cannot be private. Once declared it is available everywhere (similar to Class modules).
The best place to declare them is in the Process_Globals routine in the Main module.
Let us reuse the example with the data of a person.
Instead of declaring each parameter separately, we can define a personal type variable with the
Type keyword:
Public NbUsers = 10 As Int
Type Person(LastName As String, FirstName As String. Address As String, City As String)
Public User(NbUsers) As Person
Public CurrentUser As Person
The new personal type is Person , then we declare either single variables or arrays of this personal
type.
To access a particular item use following code.
CurrentUser.FirstName
CurrentUser.LastName
User(1).LastName
User(1).FirstName

Do you see where you did the error?
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
@DonManfred I think its works.
do you have different ways, more simple.

B4X:
Dim a1 As MyPage
    a1.Initialize
    Dim eml(2) As email2
    Dim nn(2) As Nickname
    eml(0).Initialize
    eml(0).adress="as@yah"
    eml(0).capacity=1
    eml(0).server="ser1"
    eml(1).Initialize
    eml(1).adress="qqas@yah"
    eml(1).capacity=2
    eml(1).server="ser2"
  
    nn(1).Initialize
    nn(1).Name="name1"
    nn(1).nick="nickname1"
    nn(1).shortnick="shrt name1"
    nn(0).Initialize
    nn(0).Name="name2"
    nn(0).nick="nickname2"
    nn(0).shortnick="shrt name2"
  
    a1.e_Mail=eml
    a1.Nick_name=nn
    a1.password="12323"
    a1.User="user"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I see you saw the problem ;-) Fine

No i dont have a shorter idea.

What you can do is to write small helper method which get all the needed information and which fills the values to the right key. maybe the sub will change a global list or even just "fill" one Type and return the new - filled - typevariable.
It´s up to you

Go on; you´re on the right track
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
I see you saw the problem ;-) Fine

No i dont have a shorter idea.

What you can do is to write small helper method which get all the needed information and which fills the values to the right key. maybe the sub will change a global list or even just "fill" one Type and return the new - filled - typevariable.
It´s up to you

Go on; you´re on the right track

Thank you @DonManfred , I will follow the advice.;)
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Now;

I want to record on phone for this specila type.
and
I wirete some code.
B4X:
   dim rehber as list
   rehber.Initialize  
  dim xrehber as list
   xrehber.Initialize

  rehber.add(a1)
'
' many times....
'
rehber.add(a1) ' orginal record 147 with a1*147 pcs  ///  and rehber size=147 mod count =590

   File.WriteList(File.DirDefaultExternal,"my.dat",rehber)
   DoEvents
    DoEvents
    DoEvents
Dim xrehber As List
xrehber= File.ReadList(File.DirDefaultExternal,"my.dat") 'it has 1029 record //////  and rehber size=1029 mod count =1029,
' and I saw it is divide my types.


I cant read again correctly. how can i fix?
This Questions for expert;)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This Questions for expert;)

Not really. You just need to read the documentation (see the notes at writelist)

File.WriteList(File.DirDefaultExternal,"my.dat",rehber)
You should use writeobject (and readobject) instead of writelist (and readlist).
writelist will only work with string lists
 
Upvote 0
Top