Page 1 of 2
how to use a backslash in a textlabel
Posted: Mon Dec 13, 2021 7:46 pm
by seal58
Hi there,
I want to use a backslash within the text of a label. That results in a compiler error "unclosed string literal".
Do I really have to use SetText() to fill that label, for example within initialize section?
I assumed, a text label could contain any kind of text.
Roland
Re: how to use a backslash in a textlabel
Posted: Mon Dec 13, 2021 8:31 pm
by ColinP
Try \\ instead of \.
Re: how to use a backslash in a textlabel
Posted: Mon Dec 13, 2021 8:43 pm
by seal58
\\ solves the compiler error, but it is show in the text label as \\.
Re: how to use a backslash in a textlabel
Posted: Mon Dec 13, 2021 9:44 pm
by ColinP
Strange, in my quick test in VMD \\ produces \ in a Text Label.
...
- backslashtest.png (65.61 KiB) Viewed 2886 times
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 12:33 pm
by UrbanCyborg
That's Windows behavior. Is the target platform here actually Windows?
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 12:48 pm
by seal58
Hi ColinP,
it's confusing. In VMD Editor double backslash is shown as "\\" but in the debugger as "\".
- double backslash in VMD editor
- backslash in a text label 2.jpg (4.39 KiB) Viewed 2872 times
However your hint really helps me. Thank you for quick response.
Roland
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 4:00 pm
by ColinP
UrbanCyborg wrote: ↑Tue Dec 14, 2021 12:33 pm
That's
Windows behavior. Is the target platform here actually
Windows?
I don't think it's anything specific to Windows. \ is the escape character in C strings, so its use goes back to at least 1972. It may even have been part of B, or even ALGOL which takes us back to 1958.
So \\ = \, \" = ", \n = newline, \0 = null and such like.
Java uses the same convention.
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 4:12 pm
by ColinP
seal58 wrote: ↑Tue Dec 14, 2021 12:48 pm
it's confusing. In VMD Editor double backslash is shown as "\\" but in the debugger as "\".
Hi Roland,
I'm presuming that the VMD editor works as a frontend pre-processor that spits out Java from the dialog fields verbatim.
So anything you type in the text label field will simply be wrapped in "" and fed to the compiler. At least that's my guess about how it works but I'm not 100% sure.
Do you mean you are getting different results in VM proper and VMD's test client? Unfortunately they don't match in some cases, so I always consider VM proper as the benchmark testing environment as that's what end users see.
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 4:28 pm
by seal58
Hi Colin,
by now I'm still working on java script for that module. I did not publish it yet.
You are right. VMD debugger works rather slowly and sometimes it shows GUI not exactly as it should do. So one need to publish an item in order to see and test in within VM.
Again and again I esteem forums like this very much because there are many helpful people like you. Thank you again.
Roland
Re: how to use a backslash in a textlabel
Posted: Tue Dec 14, 2021 4:40 pm
by ColinP
I double checked and as I thought the dialog field is copied verbatim into the automatically generated code in the method initializeControls()...
textLabel1 = new VoltageLabel( "textLabel1", "textLabel1", this, "test \\ test" );