B4J Question Not even sure what I need - pick out text

Tom2525

Member
Licensed User
Longtime User
This is my first time using B4J. I have a need to import a text file, have the program go through the text and then take the ASCII text then on the UI side it would show a 1 or 0 or green or red.

Eventually it will show the entire file so you can see where the text changes and displays the time it changed but for now to start small, just want to pick one piece of text and see how to display it. Is there a small working program that can get me started?
 

aeric

Expert
Licensed User
Longtime User
Check this tutorial:

Maybe you need to use File.ReadString or File.ReadList
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Something like this

Use Textreader:
        Dim TR As TextReader
        TR.Initialize(File.OpenInput(File.DirApp, Your filename))
        Dim Line As String = TR.ReadLine
        Do While Line <> Null
            Line = TR.ReadLine
            Log(Line)
        Loop
        If TR.IsInitialized = True Then
            TR.Close
        End If
omething like this.
 
Upvote 0

Tom2525

Member
Licensed User
Longtime User
Thanks for the replies. It's the basics I'm having trouble with - still trying to understand what the B4J needs to run. Starting small, I have some text and numbers on a .txt file. It's in my files folder. How can I get that information to display on a pop-up box, form, etc to know that I'm able to import the data? I get errors right now.

B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region


Sub Process_Globals


Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView

End Sub





Sub AppStart (Form1 As Form, Args() As String)

MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show

End Sub


   
Sub Button1_Click

Dim TR As TextReader
TR.Initialize(File.OpenInput(File.DirApp, "file_test.txt"))
Dim Line As String = TR.ReadLine
Do While Line <> Null
Line = TR.ReadLine
Log(Line)
Loop

 If TR.IsInitialized = True Then
TR.Close
End If
'Dim s As String = File.ReadString(File.DirApp, "file_test.txt")

xui.MsgboxAsync(TR, "PIU")


End Sub
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
It's in my files folder.
If your txt file is inside your project's Files folder then you need to use File.DirAssets
B4X:
Dim s As String = File.ReadString(File.DirAssets, "file_test.txt")
 
Upvote 0

Tom2525

Member
Licensed User
Longtime User
Dim s As String = File.ReadString(File.DirAssets, "file_test.txt")
Awesome. That worked. Now I have something to start working with. Thanks.

I did notice that with a larger file the program freezes. Is there a limit to how big the file can be? Maybe in a text box there's a limit but in a different format it would be okay?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Are you using TextArea view?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Are you trying to write a 'Diff' type output?. Probably easier to use an existing java library for it like Java-diff-utils (tiny at 77KB) and uses Meyer algo to do it.
 
Upvote 0
Top