So, my snippet looks like this:
B4X:Private Sub Delete$Controller$ (id As Long) ' #Version = v2 ' #Desc = Delete Item in MinimaList ' #Elements = [":id"] If id < 1 Then HRM.ResponseError = "Invalid id value" HRM.ResponseCode = 404 Else Dim Index As Int = Main.$MinimaList$.IndexFromId(id) If Index < 0 Then HRM.ResponseError = "Item not found" HRM.ResponseCode = 404 Else Main.$MinimaList$.Remove(Index) HRM.ResponseCode = 200 End If End If If Main.SimpleResponse Then WebApiUtils.ReturnSimpleHttpResponse(HRM, "List", Response) Else WebApiUtils.ReturnHttpResponse(HRM, Response) End If If Main.KVS_ENABLED Then Main.WriteKVS("$MinimaList$", Main.$MinimaList$) End Sub
The IDE will highlight the variables. Once I replace the first variable, all other variables (with the same placeholder) will be replaced.
before:
View attachment 146183
after:
View attachment 146184
Note that the special $end$ marking sets the cursor position after the developer set the placeholders.
Thanks. i just realized there is a tutorial.Don't forget the useful...
How easy is B4X... ehhh ?Thanks. i just realized there is a tutorial.
I done my snippets without a tutorial. ?
To me, that sounds like coding with one hand tied behind your back... I'm really curious, what do you do instead?(Same as I have never used the built in Debugger).
maybe this is call "single-handedly"To me, that sounds like coding with one hand tied behind your back... I'm really curious, what do you do instead?
There is one issue with the variable placeholder.[OK]...Now the bad news... we must re-write all the threads with the snippets and change the "variables" with $variable$ !!!, and preferable at the first post attach a txt file snippet ! ?
For eg.why ?... will not be a problem... because smart string literal... got following quote or "{"
B4X:$" ${
I am sure that Erel... count them all..
' Return Web Page
Private Sub ShowPage
Dim strMain As String = WebApiUtils.ReadTextFile("main.html")
Dim strView As String = WebApiUtils.ReadTextFile("category.html")
strMain = WebApiUtils.BuildDocView(strMain, strView)
strMain = WebApiUtils.BuildHtml(strMain, Main.config)
Dim strScripts As String = $"<script src="${Main.ROOT_URL}/assets/js/webapicategory.js"></script>"$
strMain = WebApiUtils.BuildScript(strMain, strScripts)
WebApiUtils.ReturnHTML(strMain, Response)
End Sub
Dim strScripts As String = "<script src=""" & Main.ROOT_URL & "/assets/js/controller.js""></script>"
You mean... if you have into a snippet-text file the whole sub ?For eg.
I have this code:
B4X:' Return Web Page Private Sub ShowPage Dim strMain As String = WebApiUtils.ReadTextFile("main.html") Dim strView As String = WebApiUtils.ReadTextFile("category.html") strMain = WebApiUtils.BuildDocView(strMain, strView) strMain = WebApiUtils.BuildHtml(strMain, Main.config) Dim strScripts As String = $"<script src="${Main.ROOT_URL}/assets/js/webapicategory.js"></script>"$ strMain = WebApiUtils.BuildScript(strMain, strScripts) WebApiUtils.ReturnHTML(strMain, Response) End Sub
The snippet highlighted: "<script src="
to solve it, I need to use the old way of concantenation.
B4X:Dim strScripts As String = "<script src=""" & Main.ROOT_URL & "/assets/js/controller.js""></script>"
For the string literal you can use extra $ signs.dim $var$ as string
dim str as string = $$"this is a string litaral with variable $$${$$var$$}$ in it"$$
Dim myvar As String
Dim str As String = $"this is a string litaral with variable ${myvar} in it"$
The choices for a good delimiter character are limited...It does seem somewhat painful when you consider smart string literals. Considering this is a beta, perhaps Erel will change the format from $this$ to @this@ or #this#, or something else that makes more sense.
I'm really curious, what do you do instead?
So basically you're playing the game in hard mode. ? I hear the level endboss is coding without Log() and disabling stacktraces. ?A simple Log(..) and the stacktrace is all I need to correct errors. (Old school mainframe programmer - it's just how I learnt to debug)
@Erel
There are two ways to add new snippets:
- Inside a b4xlib library. Simply add a folder named Snippets and put the snippets files in that folder. Each snippet in its own text file.
- Under the Snippets folder in the additional libraries folder. Each snippet in a separate txt file.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?