how to use macro to make my code
-
@alan-kilborn said in how to use macro to make my code:
as IMO the OP hasn’t made it very clear
Since the OP deleted their question and it had to be resurrected, I am pretty sure either the OP got the answer they needed, or they left in a huff because they couldn’t figure out how to make us understand what they wanted. Either way, I doubt the OP is going to come back and clarify, and I doubt there’s much point in our spending any more time on it (unless the OP does come back and clarify).
-
@peterjones said in how to use macro to make my code:
OP deleted their question and it had to be resurrected
@igor-lerinc A rather anti-social thing to do.
@peterjones said in how to use macro to make my code:
I doubt there’s much point in our spending any more time on it
I realized this morning an enhancement to the spreadsheet approach I suggested earlier I’d like to briefly describe.
Without too much difficulty a column could be added consisting of formulas to calculate the line number in the target file to be assembled.
Assuming 6 lines per case (1 for “case” stmnt, 4 vars, and 1 for static “break” stmnt),
the first bank, the “case” numbers, would have target line numbers 1,7,13… (1+(92-1)*6)
the second bank, the “country” fields would have target line numbers 2,8,14… (2+(92-1)*6)
etc.
Now the lines could be sorted, either in the spreadsheet or after xfer to text editor.
To make it amenable to upkeep and modification, one should define things like NUM_COUNTRIES (92) and LINES_PER_CASE (6 in my example), and use those in the formulas.
As before, there are many variations on implementation details, such as, doing C-ification early, in spreadsheet:
CONCAT spaces/tabs + "case " + case num " “:”
CONCAT spaces/tabs + “country=” + country text + “;”
etc
or late, in Npp using fancy regex in a F&R. -
this was the answer i was looking for:
https://stackoverflow.com/a/70632134/17848947
i just didn’t wanted to continue building on more misunderstandings trying to explain further and waste anyone’s time…
-
Hello, @igor-lerinc, @peterjones, @alan-kilborn, @neil-schipper, @paul-wormer and All;
I found out a nice solution with a minimum of actions to proceed ! This further method is rather difficult to express but is finally easy to execute :-))
I will expose my method with a short list of
6countries ( Andorre, United Arab Emirates, Afganistan, Albania, Armenia and Angola ) which, of course, can be extend to your230items and even more !Basically, you have three informative zones and two pseudo-zones
case n;andR.drawable.flag_+ the current country code, located on the next lineLet’s place each of these
5zones in a different file, from fileA.txtto fileE.txt. Presently, the filesB,CandEwill contain6informative lines and filesAandDare still empty !
-
In the
B.txtfile :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
2 -
Increase by
5 -
Repeat
1 -
Tick the
Leading zerosoption -
Click on the
OKbutton
-
=> You should get the numbering :
02, 07, 12, 17, 22, 27-
In the
C.txtfile :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
3 -
Increase by
5 -
Repeat
1 -
Tick the
Leading zerosoption -
Click on the
OKbutton
-
=> You should get the numbering :
03, 08, 13, 18, 23, 28-
In the
E.txtfile :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
5 -
Increase by
5 -
Repeat
1 -
Tick the
Leading zerosoption -
Click on the
OKbutton
-
=> You should get the numbering :
05, 10, 15, 20, 25, 30-
In the
D.txtempty file :-
Hit
6times on theEnterkey -
Insert a
semicoloncharacter on each line -
Move to the very beginning of file
-
Create a zero-length rectangular selection onto these
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
4 -
Increase by
5 -
Repeat
1 -
Tick the
Leading zerosoption -
Click on the
OKbutton
-
=> You should get the numbering :
04, 09, 14, 19, 24, 29, followed with a semicolon-
Finally, in the
A.txtempty file :-
Hit
6times on theEnterkey -
Move to the very beginning of file
-
Create a zero-length rectangular selection onto these
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
1 -
Increase by
5 -
Repeat
1 -
Tick the
Leading zerosoption -
Click on the
OKbutton
-
=> You should get the numbering :
01, 06, 11, 16, 21, 26-
Secondly :
-
Move the caret at end of the first line
-
Create, again, a zero-lengh rectangular selection onto these
6lines -
Open the Column Editor (
Alt + C) -
Choose the
Number to Insertradio button -
Initial number
1 -
Increase by
1, this time -
Repeat
1 -
Untick the
Leading zerosoption, this time -
Click on the
OKbutton
-
You should get the final numbering :
011, 062, 113, 164, 215, 266
Then, let’s merge the files, from
A.txttoE.txt, in any order, in a new tab, renamed asResul.txt, which possible blank lines in between. You obtain this text :011 062 113 164 215 266 02"ad" 07"ae" 12"af" 17"al" 22"am" 27"an" 03"+376" 08"+971" 13"+93" 18"+355" 23"+374" 28"+244" 04; 09; 14; 19; 24; 29; 05"Andorra" 10"United Arab Emirates (UAE)" 15"Afghanistan" 20"Albania" 25"Armenia" 30"Angola"- Perform a classical sort with the
Edit > Line Operations > Sort Lines Lexicographically Ascendingoption. After deleting the first possible blank lines, you’re left with theseResult.txtcontents :
011 02"ad" 03"+376" 04; 05"Andorra" 062 07"ae" 08"+971" 09; 10"United Arab Emirates (UAE)" 113 12"af" 13"+93" 14; 15"Afghanistan" 164 17"al" 18"+355" 19; 20"Albania" 215 22"am" 23"+374" 24; 25"Armenia" 266 27"an" 28"+244" 29; 30"Angola"-
Move to the very beginning of file
-
For the last time, do a zero-length rectangular selection onto the
30lines -
Delete the first two digits, hitting twice the
Deletekey
The
Resul.txtfile becomes :1 "ad" "+376" ; "Andorra" 2 "ae" "+971" ; "United Arab Emirates (UAE)" 3 "af" "+93" ; "Afghanistan" 4 "al" "+355" ; "Albania" 5 "am" "+374" ; "Armenia" 6 "an" "+244" ; "Angola"Almost finished ! Open the
Replacedialog and performs this regex S/R :SEARCH
(?-s)^(\d+)\R(.+)\R(.+)\R(.+)\R"(.+)"(\R)REPLACE
\tcase \1:\6\t\tcountry=\2\6\t\tcountry_code_number=\3\6\t\tcountry_flag=R\.drawable\.flag_\5;\6\t\tcountry_word="\5"\6\t\tbreak;\6Magically, the text is changed into :
case 1: country="ad" country_code_number="+376" country_flag=R.drawable.flag_Andorra; country_word="Andorra" break; case 2: country="ae" country_code_number="+971" country_flag=R.drawable.flag_United Arab Emirates (UAE); country_word="United Arab Emirates (UAE)" break; case 3: country="af" country_code_number="+93" country_flag=R.drawable.flag_Afghanistan; country_word="Afghanistan" break; case 4: country="al" country_code_number="+355" country_flag=R.drawable.flag_Albania; country_word="Albania" break; case 5: country="am" country_code_number="+374" country_flag=R.drawable.flag_Armenia; country_word="Armenia" break; case 6: country="an" country_code_number="+244" country_flag=R.drawable.flag_Angola; country_word="Angola" break;To end, run this second regex S/R :
SEARCH
(?s)(?!\r|\n).+REPLACE
switch (5) {\r\n$0\tdefault:\r\n\tconsole.log\(\x96Nothing here\x96\);\r\n\t}\r\nAnd here is, Igor, your expected result :
switch 5 { case 1: country="ad" country_code_number="+376" country_flag=R.drawable.flag_Andorra; country_word="Andorra" break; case 2: country="ae" country_code_number="+971" country_flag=R.drawable.flag_United Arab Emirates (UAE); country_word="United Arab Emirates (UAE)" break; case 3: country="af" country_code_number="+93" country_flag=R.drawable.flag_Afghanistan; country_word="Afghanistan" break; case 4: country="al" country_code_number="+355" country_flag=R.drawable.flag_Albania; country_word="Albania" break; case 5: country="am" country_code_number="+374" country_flag=R.drawable.flag_Armenia; country_word="Armenia" break; case 6: country="an" country_code_number="+244" country_flag=R.drawable.flag_Angola; country_word="Angola" break; default: console.log(`Nothing here`); }Best Regards
guy038
P.S. :
-
Your
Two-letterscountry, in theB.txtfile, represents theISO 3166-1 alpha-2standard for each country -
Your
Country_code_number, in theC.txtfile, represents theE_164 codesstandard for each country
Refer to this main link :
-
-
@guy038
Congratulations with your ingenious solution. Although it seems to me that an editor - any editor - is not quite the right tool for this job. It is as if you are explaining how to build a wooden chicken coop with as only tool the heel of a shoe.