Read text file into edittexts

gordon

Member
Licensed User
Longtime User
I have a text file which contains an address. I would like to put each line of the text file into separate edittext's in the view

B4X:
 Dim TextReader1 As TextReader
    TextReader1.Initialize(File.OpenInput(File.DirInternal , "Location.txt"))
    Dim line As String
    line = TextReader1.ReadLine    
   For i=0 To 3
       If i=0 Then
      edtAddress1Stored.text=line
     End If
    If i=1 Then
   edtAddress2Stored.text=line
  End If  
   If i=2 Then
   edtAddress3Stored.text=line
End If 
  If i=3 Then
   edtPostCodeStored.text=line
  End If
  line = TextReader1.ReadLine    
    Next
 
    TextReader1.Close

For the number of fields involved the above works but I was just wondering if there was a better or more efficient way of achieving this?
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Sure there is, if of course you have many fields. You can use an array of editTextBoxes. Then in your loop, simply write something like this
B4X:
editTextBox(i).text=line
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Klaus's Example

Hi,
I'm not sure,you try this example below,Klaus's Example
Best regards
Theera
 
Last edited:
Upvote 0
Top