Android Question Get some parts data from a list(ftp)

Discussion in 'Android Questions' started by appie21, Jul 23, 2015.

  1. appie21

    appie21 Active Member Licensed User

    I have a code that do a list import via ftp
    That works fine


    the file look like these UTF-8

    Name,Email, use facebook, use twitter, Hobbes
    Alice, alice@b4aa.com,true, false, cooking and lisen music
    Albert, Albert@b4aa.cn, true, true, play computer games
    ...
    Code:
    Dim List1 As List
    Dim row As  String

    List1 = 
    File.ReadList(File.DirInternal, "book.txt")

    row = List1.Get(
    1)

    Msgbox( row ,"Rij")
    What i now want is that i get only the name and Hobbies info in label from list1

    How can i do this?
     
  2. walterf25

    walterf25 Well-Known Member Licensed User

    You can use the Regex function to split the contents for example:

    If you have this:
    Name,Email, use facebook, use twitter, Hobbes
    Alice, alice@b4aa.com,true, false, cooking and lisen music
    Albert, Albert@b4aa.cn, true, true, play computer games

    you can split everything at the "," (comma) like this:

    Code:
    dim readstring as string
    dim textread1 as TextReader

    textreader1.Initialize(
    File.OpenInput(File.DirDefaultExternal,"filename.txt")) 'location where file is and name of file
    readstring = textreader1.ReadLine 'reads the first line in the file

    Do While readstring <> Null  'loops through every line in the file until it finishes.
    dim info() as string
    info = 
    Regex.Split(",", readstring)   'splits the read line at the "," (comma) it returns an array of 5 elements (zero based)
    log("name: " & info(0))
    log("hobbies: " & info(4))
    readstring = textreader1.ReadLine
    loop
    Hope this helps.

    Walter
     
    Last edited: Jul 23, 2015
    lemonisdead and DonManfred like this.
  3. appie21

    appie21 Active Member Licensed User

    It works I have only modify

    info = Regex.Split(",") into: info = Regex.Split(",",readstring)

    Many thanks!
     
  4. walterf25

    walterf25 Well-Known Member Licensed User

    Oh sorry, i missed that, but you get the idea.

    Glad it worked.

    Walter
     
  5. appie21

    appie21 Active Member Licensed User

    A little addon question

    how can i add that only get the info of line (row) 2 from the txt file? (without loop)

    I have try readstring = textreader1.ReadLine(1) but not work :(
     
  6. walterf25

    walterf25 Well-Known Member Licensed User

    Just read the file two times like this.

    Code:
    readstring = textreader1.ReadLine  'this reads the first line
    readstring = textreader1.ReadLine 'this reads the second line
     
  7. appie21

    appie21 Active Member Licensed User

    Thanks!
     
  8. walterf25

    walterf25 Well-Known Member Licensed User

    You're welcome!
     
  9. appie21

    appie21 Active Member Licensed User

    Hi


    I have a little addon question

    i have on my layout 3 Labels
    and 2 buttons

    One of the buttons is next ant the other is Back

    What I want is that the labels will be filled with the data from the textreader line 1 and if i press the button again the data from line 2 will be loaded in the labels and so on

    And if i press the back button the data from the previos line will be loaded

    Ho can I Made this?
    Code:
    Dim readstring As String
        
    Dim textreader1 As TextReader
        
    Dim info() As String
        textreader1.Initialize(
    File.OpenInput(File.DirInternal, "book.txt"))
        readstring = textreader1.ReadLine
    Do While readstring <> Null
       

        info = 
    Regex.Split(";",readstring)  
        LblReviewName1.Text = info(
    1)
        LblReviewMening1.Text = info(
    7)
        LblReviewDate1.Text = info(
    2)
        readstring = textreader1.ReadLine
       
    Loop
     
Loading...