Quick way to add hundreds of constants in a module?

Hi everyone,

I am doing some work where I need to add many constants (a few hundred) into a module, is there a quick way of adding these constants other than manually typing them into the module? This information is in the format from a C/C++ file and looks like this:

... Const DMPAPER_A5_EXTRA = 64 Const DMPAPER_A5_TRANSVERSE = 61 Const DMPAPER_B_PLUS = 58 Const DMPAPER_B4 = 12 Const DMPAPER_B5 = 13 Const DMPAPER_B5_EXTRA = 65 ...

I am hoping that there might be a cut-and-paste method? :slight_smile:

Use Excel to generate the XOJO code. Import or past them into a sheet and write a VBA function to output the code in an adjoining cell. I find it very useful for code generation.

Thanks James, I’ll try this out :slight_smile:

make some lines in a module
export as xml
see the generated text
IMHO a simple search/replace from the C code with a text editor may be enough ?

Can go one step further with a RegEx that’ll turn the C code into Xojo constants!
Just Code Challenge project?

Great ideas everyone. Thanks!

The code you posted could be pasted into a method without any changes. But as I understand it you don‘t want the constants in a method, you want them as properties of the module, so they autocomplete etc.

If that’s the case then I‘m not sure why James Dooley‘s response is marked as the answer as it won‘t do what you asked.

Jean-Yves Pochez response does what you asked.

Of course it will. The VBA function generates the code needed to create a constant in an XOJO source file. Once you have it, you open the module file in a text editor paste it in, save the file, reopen it in the IDE and you have the constants in their usual place in the tree on the left.

This is what a constant looks like the source:

#tag Constant, Name = kTableName, Type = String, Dynamic = False, Default = “folder”, Scope = Protected
#tag EndConstant

Easy to write a VBA function to parse the C statement and output this stuff.

[quote=402704:@Markus Winter]The code you posted could be pasted into a method without any changes. But as I understand it you don‘t want the constants in a method, you want them as properties of the module, so they autocomplete etc.

If that’s the case then I‘m not sure why James Dooley‘s response is marked as the answer as it won‘t do what you asked.

Jean-Yves Pochez response does what you asked.[/quote]
Thanks Markus,

All three responses (James, Jean-Yves, and Tim’s) responses will work, and thank you for the replies. I marked James as the answer because he was first, that’s all.

Much appreciated :slight_smile:

[quote=402705:@James Dooley]Of course it will. The VBA function generates the code needed to create a constant in an XOJO source file. Once you have it, you open the module file in a text editor paste it in, save the file, reopen it in the IDE and you have the constants in their usual place in the tree on the left.

This is what a constant looks like the source:

#tag Constant, Name = kTableName, Type = String, Dynamic = False, Default = “folder”, Scope = Protected
#tag EndConstant

Easy to write a VBA function to parse the C statement and output this stuff.[/quote]

That will do it, and is close to what Yves suggested. What was missing in your original answer (and what Yves added) was that you need to export it to a Xojo source file - that is essential information in this context.

The answer was already given n the forum, some years ago.