B4R Question can we make a B4RString with a text on multiple lines?

candide

Active Member
Licensed User
possible it is simple but i didn't find the solution : can we make a string or byte array with a text on multiple lines like in arduino ?

arduino example :
B4X:
const char MAIN_page[] PROGMEM = R"=====(
<!DOCTYPE html>
<html>
<style>
.card{
    max-width: 400px;
     min-height: 250px;
     background: #02b875;
     padding: 30px;
     box-sizing: border-box;
     color: #FFF;
     margin:20px;
     box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
}
</style>
<body>

<div class="card">
  <h4>The ESP32 Update web page without refresh</h4><br>
  <h1>Sensor Value:<span id="ADCValue">0</span></h1><br>
  <br><a href="https://circuits4you.com">Circuits4you.com</a>
</div>
</body>
</html>
)=====";
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no smart string in B4R. You can define the string with inline C code:
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private text As String = "aa"
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    Log(text)
    RunNative("getMainPage", Null)
    Log(text)    
    RunNative("getSecondPage", Null)
    Log(text)
End Sub


#if c
const char MAIN_page[]  = R"=====(
<!DOCTYPE html>
<html>
<style>
.card{
    max-width: 400px;
     min-height: 250px;
     background: #02b875;
     padding: 30px;
     box-sizing: border-box;
     color: #FFF;
     margin:20px;
     box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
}
</style>
<body>

<div class="card">
  <h4>The ESP32 Update web page without refresh</h4><br>
  <h1>Sensor Value:<span id="ADCValue">0</span></h1><br>
  <br><a href="https://circuits4you.com">Circuits4you.com</a>
</div>
</body>
</html>
)=====";

const char SECOND_page[]  = R"=====(
this is 
the 
second page
</html>
)=====";
static B4R::B4RString temp_s;
B4R::Object* getMainPage(B4R::Object* o) {
   b4r_main::_text = temp_s.wrap(MAIN_page);
}
B4R::Object* getSecondPage(B4R::Object* o) {
   b4r_main::_text = temp_s.wrap(SECOND_page);
}
#End If

Note that I removed the progmem flag.
 
Upvote 0

candide

Active Member
Licensed User
thanks for your answer.

an other way inside B4R can be to use an array of string :
B4X:
    Dim autho() As String =Array As String( _
    "<html>", _
    "<head>", _
    "<meta charset=""utf-8"">", _
    "<style>", _
    "body{ background: #67BE4B; }", _
    "#container{ width:400px; margin:0 auto; margin-top:10%; }", _
    "form { width:100%; padding: 30px; border: 1px solid #f1f1f1; background: #fff; box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24); }", _
    "#container h1{ width: 38%; margin: 0 auto; padding-bottom: 10px; }", _
    "input[type=submit] { background-color: #53af57; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 100%; }", _
    "input[type=submit]:hover { background-color: white; color: #53af57; border: 1px solid #53af57; }", _
    "input[type=text], input[type=password] { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; box-sizing: border-box; }", _
    "</style>", _
    "</head>", _
    "<body>", _
   "..........................................

but modifications of text are needed to create lines...

inline C is better to preserve text like it is in a file
Thanks
 
Upvote 0
Top