Most recent edit on 2007-05-18 21:57:55 by FrankVanHerreweghe [typo ;-)]
Additions:
Update C Expr: (A-1)/676
Deletions:
Update C Expr: A/676
Edited on 2007-05-17 17:26:33 by FrankVanHerreweghe [solved a bug :-)]
Additions:
Update C Expr: A/676
Update D Expr: Fix ((A-Fix ((A-1)/676,5,0)*676-1)/26,5,0)
Update E Expr: (A-1) MOD 26
Deletions:
Update C Expr: Fix (IF (A<677,0,(A-1)/676),5,0)
Update D Expr: Fix (IF (A<27,0,IF (A<677,(A-1)/26,(A-677)/26)),5,0)
Update E Expr: Fix ((A-1) MOD 26,5,0)
Edited on 2006-06-21 21:00:37 by GroupsMBM [Fixed unintended wiki link]
Additions:
How to Generate a 3-letter MagicVariable out of a Number
Deletions:
How to Generate a 3-letter MagicVariable out of a Number
Edited on 2005-09-03 23:02:27 by FrankVanHerreweghe
Additions:
I also received a nice theoritical look (and a program) on this routine from T.M. (thx)
select param "A" Source Number Num 5
select param "B" Magic Var ID Alpha 3
select virtual "C" 1's Number Num 2
select virtual "D" 26's Number Num 2
select virtual "E" 676's Number Num 2
update C (1's Number) Expr: A-1 MOD 26
update D (26's Number) Expr: ((A-(C+1)) MOD 676) / 26
update E (676's Number) Expr: A-((D*26)+C+1) / 676
update B (Magic Var ID) Expr: IF(E=0,' ',Chr(65+E)) & IF(D=0 AND E=0,' ',Chr(65+D)) & Chr(65+C)
Deletions:
I also received a nice theoritical look (and a program) on this routine from T.M.
Program follows later...
Edited on 2005-09-03 22:57:08 by FrankVanHerreweghe
Additions:
Select Parameter i-VariableNumber "A" Num 5
Select Parameter o-VariableString "B" Alpha U3
Select Virtual v-NumPart1 "C" Num 5
Select Virtual v-NumPart2 "D" Num 5
Select Virtual v-NumPart3 "E" Num 5
Select Virtual v-Part1 "F" Alpha U
Select Virtual v-Part1 "G" Alpha U
Select Virtual v-Part1 "H" Alpha U
Update C Expr: Fix (IF (A<677,0,(A-1)/676),5,0)
Update D Expr: Fix (IF (A<27,0,IF (A<677,(A-1)/26,(A-677)/26)),5,0)
Update E Expr: Fix ((A-1) MOD 26,5,0)
Update F Expr: CHR (C+65) Cnd: A>676
Update G Expr: CHR (D+65) Cnd: A>26
Update H Expr: CHR (E+65)
Update B Expr: Trim (F)&Trim (G)&Trim (H)
I also received a nice theoritical look (and a program) on this routine from T.M.
Deletions:
Select Parameter i-VariableNumber "BA" Num 5
Select Parameter o-VariableString "BB" Alpha U3
Select Virtual v-NumPart1 "BC" Num 5
Select Virtual v-NumPart2 "BD" Num 5
Select Virtual v-NumPart3 "BE" Num 5
Select Virtual v-Part1 "BF" Alpha U
Select Virtual v-Part1 "BG" Alpha U
Select Virtual v-Part1 "BH" Alpha U
Update BC Expr: Fix (IF (BA<677,0,(BA-1)/676),5,0)
Update BD Expr: Fix (IF (BA<27,0,IF (BA<677,(BA-1)/26,(BA-677)/26)),5,0)
Update BE Expr: Fix ((BA-1) MOD 26,5,0)
Update BF Expr: CHR (BC+65) Cnd: BA>676
Update BF Expr: CHR (BD+65) Cnd: BA>26
Update BF Expr: CHR (BE+65)
Update BB Expr: Trim (BF)&Trim (BG)&Trim (BH)
I received a nice theoritical look on this routine from T.M.
Edited on 2005-09-03 14:14:28 by FrankVanHerreweghe
Additions:
The record main will look like this:
The record suffix will look like this:
Well, it seems to me that Magic's method of lettering variables is really
Deletions:
Record Main:
Record Suffix:
Well, it seems to me that Magic's method of lettering variables is really
Oldest known version of this page was edited on 2005-09-03 14:12:02 by FrankVanHerreweghe []
Page view:
How to Generate a 3-letter MagicVariable out of a Number
This routine can be used in a debugger to generate the Magic Variablenames or when you generate some exportfiles of a program yourself.
Task properties: Batch
EndTask: Yes/Before
Record Main:
Select Parameter i-VariableNumber "BA" Num 5
Select Parameter o-VariableString "BB" Alpha U3
Select Virtual v-NumPart1 "BC" Num 5
Select Virtual v-NumPart2 "BD" Num 5
Select Virtual v-NumPart3 "BE" Num 5
Select Virtual v-Part1 "BF" Alpha U
Select Virtual v-Part1 "BG" Alpha U
Select Virtual v-Part1 "BH" Alpha U
Record Suffix:
Update BC Expr: Fix (IF (BA<677,0,(BA-1)/676),5,0)
Update BD Expr: Fix (IF (BA<27,0,IF (BA<677,(BA-1)/26,(BA-677)/26)),5,0)
Update BE Expr: Fix ((BA-1) MOD 26,5,0)
Update BF Expr: CHR (BC+65) Cnd: BA>676
Update BF Expr: CHR (BD+65) Cnd: BA>26
Update BF Expr: CHR (BE+65)
Update BB Expr: Trim (BF)&Trim (BG)&Trim (BH)
I received a nice theoritical look on this routine from T.M.
Well, it seems to me that Magic's method of lettering variables is really
just another numbering system like binary, decimal, or hexadecimal. I
certainly don't know what the name would be for base 26, but this is pretty
much what's going on.
Some special considerations:
1. Magic starts counting at one, while numeric systems start counting at
zero. The formulas will have to be adjusted for that.
2. The first variable in the stack is really "AAA" (= to 000), but magic
doesn't show the leading "A" characters (like we don't usually show leading
0 digits).
Numeric systems are based upon exponential math.
Decimal:
10^0 = 1
10^1 = 10
10^2 = 100
10^3 = 1000
Binary:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
etc.
Magic: (base 26)
26^0 = 1
26^1 = 26
26^2 = 676
Considering that "A" in magic is equal to 0 in decimal....
If we wanted to go from magic variable name "CDB" to a number, we would:
Multiply the "B" (decimal equivalent of 1) * 1 = 1
Multiply the "D" (decimal equivalent of 3) * 26 = 78
Multiply the "C" (decimal equivalent of 2) * 676 = 1352
Sum the three products 1 + 78 + 1352 = 1431, and add 1 (because magic
starts at one, not zero), so the value CDB (magic) = 1432 (decimal)
Doing that backwards? From Right to Left (ones, 26's, 676's)
Start with = 1432
Subtract 1 = 1431
Mod 26 = 1 (the 1's column)
subtract this = 1420
mod 676 = 78
divide by 26 = 3 (the 26's column)
subtract 78 from 1420 = 1352
divide by 676 = 2 (the 676's column)
Program follows later...
regards
Frank Van Herreweghe
Category
CategoryHowTo