how to use a backslash in a textlabel

User avatar
seal58
Posts: 354
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

how to use a backslash in a textlabel

Post 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
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: how to use a backslash in a textlabel

Post by ColinP »

Try \\ instead of \.
User avatar
seal58
Posts: 354
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

Re: how to use a backslash in a textlabel

Post by seal58 »

\\ solves the compiler error, but it is show in the text label as \\.
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: how to use a backslash in a textlabel

Post by ColinP »

Strange, in my quick test in VMD \\ produces \ in a Text Label.
...
backslashtest.png
backslashtest.png (65.61 KiB) Viewed 1722 times
UrbanCyborg
Posts: 599
Joined: Mon Nov 15, 2021 9:23 pm

Re: how to use a backslash in a textlabel

Post by UrbanCyborg »

That's Windows behavior. Is the target platform here actually Windows?
Cyberwerks Heavy Industries -- viewforum.php?f=76
User avatar
seal58
Posts: 354
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

Re: how to use a backslash in a textlabel

Post 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
double backslash in VMD editor
backslash in a text label 2.jpg (4.39 KiB) Viewed 1708 times
However your hint really helps me. Thank you for quick response.

Roland
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: how to use a backslash in a textlabel

Post 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.
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: how to use a backslash in a textlabel

Post 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.
User avatar
seal58
Posts: 354
Joined: Fri Jul 12, 2019 5:28 pm
Location: Rostock, Germany
Contact:

Re: how to use a backslash in a textlabel

Post 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
ColinP
Posts: 951
Joined: Mon Aug 03, 2020 7:46 pm

Re: how to use a backslash in a textlabel

Post 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" );
Post Reply

Return to “Module Designer”