Book a Demo

Author Topic: MDA macros: Compare strings?  (Read 2861 times)

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
MDA macros: Compare strings?
« on: April 05, 2011, 09:43:30 pm »
In order to realize proper n:m relations for two entites I need to compare both entity names to build the jointable's name. The entity that comes first in the alphabetical order must be the first part of the composite name (e.g. TypeA and TypeB -> TypeA_m2m_TypeB). The problem at the moment is that the direction of the connector between both entities determines the order (a bidirectional aggregation connector drawn from TypeB to TypeA results in TypeB_n2m_TypeA).

How can I do this with MDA macros? I can't find a function macro for that, also there are no arithmetic operations which I could use to write a compare function macro. Any ideas about a workaround?

pocketom

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: MDA macros: Compare strings?
« Reply #1 on: April 05, 2011, 11:02:54 pm »
I've "managed" to write a small workaround, but my boss shouldn't see this...

function compare(stringA, stringB)
Code: [Select]
$stringA=%TO_UPPER($parameter1)%
$stringB=%TO_UPPER($parameter2)%
$charA=%LEFT($stringA,"1")%
$charB=%LEFT($stringB,"1")%
$order=%compare_single_char($charA,$charB)%
%if $order == "0"%
$trimA=%TRIM_LEFT($stringA,$charA)%
$trimB=%TRIM_LEFT($stringB,$charB)%
%if $trimA=="" and $trimB==""%
0
%elseIf $trimA==""%
-1
%elseIf $trimB==""%
1
%else%
%compare($trimA,$trimB)%
%endIf%
%else%
$order
%endIf%

function compare_single_char()
Code: [Select]
$charA=%TO_UPPER($parameter1)%
$charB=%TO_UPPER($parameter2)%
%if $charA == $charB%
0
%else%
$nextAscCharA=%compare_alphabet($charA,"ASC")%
%if $nextAscCharA == $charB%
-1
%elseIf $nextAscCharA == "MAX"%
1
%else%
%compare_single_char($nextAscCharA,$charB,"ASC")%
%endIf%
%endIf%

function compare_alphabet
Code: [Select]
$compareChar=%TO_UPPER($parameter1)%
$mode=%TO_UPPER($parameter2)%
%if $mode=="ASC"%
%if $compareChar == "_"%
-
%elseIf $compareChar == "-"%
0
%elseIf $compareChar == "0"%
1
%elseIf $compareChar == "1"%
2
%elseIf $compareChar == "2"%
3
%elseIf $compareChar == "3"%
4
%elseIf $compareChar == "4"%
5
%elseIf $compareChar == "5"%
6
%elseIf $compareChar == "6"%
7
%elseIf $compareChar == "7"%
8
%elseIf $compareChar == "8"%
9
%elseIf $compareChar == "9"%
A
%elseIf $compareChar == "A"%
B
%elseIf $compareChar == "B"%
C
%elseIf $compareChar == "C"%
D
%elseIf $compareChar == "D"%
E
%elseIf $compareChar == "E"%
F
%elseIf $compareChar == "F"%
G
%elseIf $compareChar == "G"%
H
%elseIf $compareChar == "H"%
I
%elseIf $compareChar == "I"%
J
%elseIf $compareChar == "J"%
K
%elseIf $compareChar == "K"%
L
%elseIf $compareChar == "L"%
M
%elseIf $compareChar == "M"%
N
%elseIf $compareChar == "N"%
O
%elseIf $compareChar == "O"%
P
%elseIf $compareChar == "P"%
Q
%elseIf $compareChar == "Q"%
R
%elseIf $compareChar == "R"%
S
%elseIf $compareChar == "S"%
T
%elseIf $compareChar == "T"%
U
%elseIf $compareChar == "U"%
V
%elseIf $compareChar == "V"%
W
%elseIf $compareChar == "W"%
X
%elseIf $compareChar == "X"%
Y
%elseIf $compareChar == "Y"%
Z
%elseIf $compareChar == "Z"%
MAX
%else%
ERR
%endIf%
%elseIf $mode=="DESC"%
%if $compareChar == "_"%
MIN
%elseIf $compareChar == "-"%
_
%elseIf $compareChar == "0"%
-
%elseIf $compareChar == "1"%
0
%elseIf $compareChar == "2"%
1
%elseIf $compareChar == "3"%
2
%elseIf $compareChar == "4"%
3
%elseIf $compareChar == "5"%
4
%elseIf $compareChar == "6"%
5
%elseIf $compareChar == "7"%
6
%elseIf $compareChar == "8"%
7
%elseIf $compareChar == "9"%
8
%elseIf $compareChar == "A"%
9
%elseIf $compareChar == "B"%
A
%elseIf $compareChar == "C"%
B
%elseIf $compareChar == "D"%
C
%elseIf $compareChar == "E"%
D
%elseIf $compareChar == "F"%
E
%elseIf $compareChar == "G"%
F
%elseIf $compareChar == "H"%
G
%elseIf $compareChar == "I"%
H
%elseIf $compareChar == "J"%
I
%elseIf $compareChar == "K"%
J
%elseIf $compareChar == "L"%
K
%elseIf $compareChar == "M"%
L
%elseIf $compareChar == "N"%
M
%elseIf $compareChar == "O"%
N
%elseIf $compareChar == "P"%
O
%elseIf $compareChar == "Q"%
P
%elseIf $compareChar == "R"%
Q
%elseIf $compareChar == "S"%
R
%elseIf $compareChar == "T"%
S
%elseIf $compareChar == "U"%
T
%elseIf $compareChar == "V"%
U
%elseIf $compareChar == "W"%
V
%elseIf $compareChar == "X"%
W
%elseIf $compareChar == "Y"%
X
%elseIf $compareChar == "Z"%
Y
%endIf%
%endIf%

The last one is my favorite ^^

If anybody finds a bug, please feel free to report it in this thread  ;)

So, next task is implementing BubbleSort using the all new compare feature... :P
« Last Edit: April 05, 2011, 11:13:57 pm by pocketom »