Android Question how to show b4x code in b4x

Mehrzad238

Active Member
Hello, if I want to show a sub like this in B4X project as text in a label or any textview, how should I do that?

I mean, know that if I put even a whole class in a text file, I can show it like this:
B4X:
dim code as string=$"${File.ReadString(File.DirAssets,"code.txt")}"$)

But when I want to show a sub in B4X or if it's multiple subs in it, that is a problem.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You haven't posted the problematic code. I guess that you are referring to something like this:
B4X:
Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    Dim s As String = $"
Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub
"$
End Sub
The above code will fail to compile because the parser will reject it. It is related to an important parser optimization.

You can do something like:
B4X:
Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    Dim s As String = $"
~Private Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
~End Sub
"$
    s = RemoveTildes(s)
    Log(s)
End Sub

Private Sub RemoveTildes (s As String) As String
    Return s.Replace(CRLF & "~", CRLF)
End Sub

BTW, check this: https://www.b4x.com/android/forum/t...e-parser-b4x-code-highlighter.109308/#content

And another option to show highlighted code is with WebView and prism: https://www.b4x.com/android/forum/t...ng-b4x-code-in-html-pages-using-prism.117448/
 
Upvote 0

Mehrzad238

Active Member

Attachments

  • codeview.bas
    7.2 KB · Views: 86
Upvote 0
Top