Adding a lot of constants

Am I doing somethings daft?

I’m trying to add a lot of constants into a test project for something, so I figured I’d add a couple then copy those into notepad, create them in the same format then paste them back into the IDE.

Can I get it to work? Can I heck.

Any tips greatly appreciated before I resort to saving the project as text and adding them via another program.

one day, I had to do that…

I exported my project to xml, including some constants, so I know how to write them. Then I load the xml, add all my constants and then reload the xml as project.

strange idea, but works fine.

This is where the Xojo editor trips you up.
You cant just paste 40 constants into a text page and have them as constants at the window or module level

Const ABC =1 Const ABD =2

I can more or less understand string constants as they are often multi-lingual
In theory, this is true of any other constant too.
Even an integer can have 3 or 4 values, and the one used depends upon language or OS

Add a module to your project, make it external as XML, add a constant, close your project, edit the xml code file duplicating the existing constant node with new name & value, re-open your project - all constants should be there, make the module internal.

Just more detail on Emile’s suggestion.

Whatks wrong with selecting the constant, then hitting copy paste paste paste …?

Nothing, maybe a bit boring ?

Thanks all, I was hoping that where was a silver bullet solution to getting the IDE to take the paste that I had been missing, I guess I’ll feedback that.

I just bit the bullet and ended up saving the project as text, closing everything down, dropping into sublime and inserting the entries by hand, nice tip on the external though Wayne, thanks.

Nothing but it’s so much slower doing bulk edits in a GUI and prone to errors compared with pasting in a block of text that has been converted into the correct format using regex :slight_smile:

[quote=375035:@]Am I doing somethings daft?

I’m trying to add a lot of constants into a test project for something, so I figured I’d add a couple then copy those into notepad, create them in the same format then paste them back into the IDE.
[/quote]
Just here to confirm you’re not dreaming, not being able to paste manipulated contents in to the IDE is a known thing. I use the phrase “thing” because I don’t know if they consider it an issue or not.

We can all find out together now, all aboard the bug bus :slight_smile:

<https://xojo.com/issue/51483>

Also, that feeling when you find another bug while reporting a bug :S

@ see the attached file in the fb 51483

There is a possibility to easy add a large number of constants, drop the attached file Module2.xojo_code in the navigator of a new (or existing) project and you will see that there is a module2 generated with 4 different numeric constants with each a different value.
To add constants open the file in a text editor and add the same lines as for the already present constants with new names and values. The same can be done with other types.

Added to the feedback 51483 also a zipped directory that can (after unzipping) been dropped in the navigator, making it also possible to add methods etc. to the navigator. I
f you drop the unzipped directory in the Chinook_Sqlite_AutoIncrementPKs.sqlite.zip-file then you will see a folder with the complete chinook database tables and fields in the navigator

I frequently have to add many constants for the many raspberry pi but-banging projects and adding a few hundered constants is tedious.

I don’t have a solution and thanks for creating a feedback case.

Nice Andre, export, modify, import.

Easy is a relative term though. It would be easy to just paste them in from notepad or https://regex101.com/ where I made the list in the first place :slight_smile:

It’s a shame that all these solutions are only for pro licence users (in essence) as exporting a module/project as text to see what the file format is in the first place is a bit tricky without pro :frowning:

@Eugene Dakin Please look at my attachments in the feedback <https://xojo.com/issue/51483>

I’ll look at the attachment when I am back at my development computer. Thanks @Andre Kuiper

Another approach (onMac) might be to use a third party Automator - Keyboard Maestro. Does not require a Pro license.

Here is an approximation of a Keyboard Macro script
It takes the contents of the Clipboard puts it in a text variable LocalManyConstant.
It then spits it out one line at a time using a For Each loop into a variable (LocalLine)
For each line then you create a new Constant in Xojo (??C) and transfer the line to the Clipboard and paste it into Xojo.
I threw in a bunch of short pauses to make sure the script does not get “ahead” of Xojo’s ability to digest the incoming info.

To start out, you copy your text document (which is nothing more than lines of contants names) onto the Clipboard and launch this macro. It will create all the contants inside of Xojo.

Activate Xojo Set Variable “LocalManyConstant” to Text %SystemClipboard% For Each LocalLine in the Collection Execute Actions The lines in Variable “LocalManyConstant” Execute the Following Actions: Type the ??C Keystroke Pause for .1 Seconds Set System Clipboard to Text %LocalLine% Pause for .1 Seconds Paste Pause for .1 Seconds