put some codes into the clipboard invalid

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
kewin
Posts: 23
Joined: 17 Dec 20, 02:45

put some codes into the clipboard invalid

Post by kewin » 30 Dec 20, 23:10

Hello everyone,

I want to put some codes into the clipboard, but it always fails. The code is as follows

When I switch from another phrase to this one, it will look like this
Image

Any suggestions are welcome. Thanks in advance

___________________________________________________________________
class Program
{
static void Main()
{

DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph(document);
section.Blocks.Add(paragraph);

Run run = new Run(document, "Hello World!");
paragraph.Inlines.Add(run);

}
}
___________________________________________________________________

Peter Stotz
PhraseExpress Expert
Posts: 914
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 09 Jan 21, 21:54

@kewin
Probably the curly braces { ... } in the code cause the issue.
Test this code:

Code: Select all

{#setclipboard class Program
{#ASC 123} void Main()
{#ASC 123}

DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph(document);
section.Blocks.Add(paragraph);

Run run = new Run(document, "Hello World!");
paragraph.Inlines.Add(run);


{#ASC 125}
{#ASC 125}}
{#insertclipboard}
Peter Stotz
Windows 10 - PhraseExpress v15.0.77

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 10 Jan 21, 07:48

@Peter Stotz
Thank you for your reply. It's very inconvenient, especially in the case of too much code

Is there a simpler and more effective solution?

In addition, I found that setting the code to a variable also cause errors
Image

Code: Select all

class Program
{
	static void Main()
	{
		// If using Professional version, put your serial key below.
		ComponentInfo.SetLicense("FREE-LIMITED-KEY");

		DocumentModel document = new DocumentModel();

		Section section = new Section(document);
		document.Sections.Add(section);

		Paragraph paragraph = new Paragraph(document);
		section.Blocks.Add(paragraph);

		Run run = new Run(document, "name");
		paragraph.Inlines.Add(run);

		document.Save("file.docx");
	}
}

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 10 Jan 21, 07:51

I'm a developer,
I want to define a lot of code Snippets, which is the biggest problem I encountered

Peter Stotz
PhraseExpress Expert
Posts: 914
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 10 Jan 21, 10:59

@kewin
What about
{
___code snippet
\\\}


Peter Stotz
Windows 10 - PhraseExpress v15.0.77

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 10 Jan 21, 13:41

@Peter Stotz

Still failed
It will be very troublesome if all } need to be manually modified to \\\}

{#setclipboard {
class Program
{
static void Main()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph(document);
section.Blocks.Add(paragraph);

Run run = new Run(document, "name");
paragraph.Inlines.Add(run);

document.Save("file.docx");
}
}
\\\} -variablename put text into clipboard}

Peter Stotz
PhraseExpress Expert
Posts: 914
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 10 Jan 21, 17:51

@kewin
The code snippet should look like this:
{#setclipboard class Program
{ void Main()
{

DocumentModel document = new DocumentModel();

Section section = new Section(document);
document.Sections.Add(section);

Paragraph paragraph = new Paragraph(document);
section.Blocks.Add(paragraph);

Run run = new Run(document, "Hello World!");
paragraph.Inlines.Add(run);

\\\}
\\\}
}

––––––––––––––––––––––––––––––––––––––––––––––––––
Still failed
It will be very troublesome if all } need to be manually modified to \\\}
I see. But what is YOUR workaround???

Peter Stotz
Windows 10 - PhraseExpress v15.0.77

kewin
Posts: 23
Joined: 17 Dec 20, 02:45

Post by kewin » 12 Jan 21, 07:33

@Peter Stotz

I have not found a better solution.

this problem, custom code phrase is very inconvenient

Peter Stotz
PhraseExpress Expert
Posts: 914
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 12 Jan 21, 20:43

@kewin
The PhraseExpress parser interprets curly braces as PhraseExpress code elements.

But never give up...
Adapt your concept!

Peter Stotz
Windows 10 - PhraseExpress v15.0.77

Peter Stotz
PhraseExpress Expert
Posts: 914
Joined: 27 Feb 08, 15:07

Post by Peter Stotz » 17 Jan 21, 20:07

@kevin
„I want to put some codes into the clipboard...“

What are the code snippets to be used for and how (your workflow) ?
I assume you want to insert prepared code snippets into a development environment to program efficiently.

My suggestion:
Put the code snippets in text files with meaningful names.
This way you can embed code snippets selectively into your development environment.
This is possible directly or indirectly via the clipboard:

Code: Select all

(* 20210117 • Codeschnipsel aus D:\Dokumente\PhraseExpress\CodeSnippets\ in die Zwischenablage einlesen
*){#setclipboard {#embedfile {#Opendlg -TITLE Bitte einen  C o d e s c h n i p s e l   a u s w ä h l e n: -DEFEXT txt -DEFFILENAME -INITDIR D:\Dokumente\PhraseExpress\CodeSnippets\}}}
(Note: you have to adjust the directory D:\Dokumente\PhraseExpress\CodeSnippets\ in my example)

Peter Stotz
Windows 10 - PhraseExpress v15.0.77

Post Reply