IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Développement d'une calculatrice


Sujet :

C#

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 37
    Par défaut Développement d'une calculatrice
    Salut à tous !

    Je développe pour m'amuser une calculatrice en C# et en utilisant Silverlight.

    Elle se compose d'un controle de type textblock ou j'affiche ma ligne de calcul, et de boutons représentant les chiffres et les signes de calcul. Chaque fois qu'un bouton est pressé, le signe ou le chiffre correspondant s'affiche dans le textblock. Jusque la rien de compliqué, cependant je rencontre un léger problème.

    Lorsque ma ligne de calcul est remplie et que je veux afficher le résultat, je clique donc sur le bouton "=" , et je voudrais qu'a ce moment la, ma ligne de calcul disparaisse du textblock, et que le résultat du calcul apparaisse à la place. Comment faire svp ?

    J'ai pensé à faire un split sur la chaine représentant mon calcul et de garder de ce fait que les chiffres et les signes, et de faire le calcul en code, mais c'est vraiment fastidieux et risqué avec l'utilisation des parenthèses pour les priorités etc...

    Je voudrais en gros une fonction qui prendrait en parametre ma chaine de caractères et en sortirait le résultat... J'ai regardé a tout hasard du coté de la classe Math mais je n'ai rien trouvé.

    Merci d'avance

  2. #2
    Rédacteur
    Avatar de Nathanael Marchand
    Homme Profil pro
    Expert .Net So@t
    Inscrit en
    Octobre 2008
    Messages
    3 615
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Expert .Net So@t
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2008
    Messages : 3 615
    Par défaut
    Mine de rien, c'est pas simple ce que tu demandes
    Le moyen authentique de le faire est d'utiliser un librairie de grammaire qui parse ton string pour en déduire un arbre. C'est à partir de cette arbre que tu pourras faire les calculs.

  3. #3
    Membre averti
    Inscrit en
    Septembre 2008
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 42
    Par défaut
    Est ce que ta calculette doit gèrer les parenthèses, les priorités, ... ?

  4. #4
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    le plus simple que j'ai trouvé c'est de passer par du sql
    si tu n'as pas de base de données c'est pas toujours simple mais peut etre bricolable ...

    il suffit alors de exécuter
    "SELECT " + textbox1.text

    et là même si tu te retrouves avec
    (((5+8)/3) +3) *8 ca passe sans se poser de questions
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    Le moyen authentique de le faire est d'utiliser un librairie de grammaire qui parse ton string pour en déduire un arbre. C'est à partir de cette arbre que tu pourras faire les calculs.
    Pour parser des expressions arithmétiques, la grammaire d'un parser LL fait 3 lignes. De plus ce n'est pas vraiment la peine de construire un arbre : le calcul peut se faire à la volée

    Voila un petit exemple (J'utilise code contract).
    Gestion de +, -, /, *, (, )
    Les espaces ne sont pas gérés
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
     
    // Grammar
    // E ::= M ((+|-)M)* | M
    // M ::= N ((*|/)N)* | N
    // N ::= [0-9]* | -E | +E | (E)
     
    public static int Parse(string s)
    {
        Contract.Requires(s != null);
        Contract.Requires(s.Length > 0);
        int pos = 0;
     
        int result = ParseE(s, ref pos);
        if (pos < s.Length)
        {
            throw new ArgumentException("s");
        }
     
        return result;
    }
     
    private static int ParseE(string s, ref int pos)
    {
        Contract.Requires(s != null);
        Contract.Requires(pos >= 0);
        Contract.Requires(pos < s.Length);
        Contract.Ensures(pos >= Contract.OldValue(pos));
     
        int result = ParseM(s, ref pos);
     
        while (pos < s.Length && (s[pos] == '+' || s[pos] == '-'))
        {
            if (s[pos] == '+')
            {
                pos++;
                TestPosition(s, pos);
                result = result + ParseM(s, ref pos);
            }
            else
            {
                pos++;
                TestPosition(s, pos);
                result = result - ParseM(s, ref pos);
            }
        }
     
        return result;
    }
     
    private static int ParseM(string s, ref int pos)
    {
        Contract.Requires(s != null);
        Contract.Requires(pos >= 0);
        Contract.Requires(pos < s.Length);
        Contract.Ensures(pos >= Contract.OldValue(pos));
     
        int result = ParseN(s, ref pos);
     
        while (pos < s.Length && (s[pos] == '*' || s[pos] == '/'))
        {
            if (s[pos] == '*')
            {
                pos++;
                TestPosition(s, pos);
                result = result * ParseN(s, ref pos);
            }
            else
            {
                pos++;
                TestPosition(s, pos);
                int div = ParseN(s, ref pos);
                if (div == 0)
                {
                    throw new DivideByZeroException();
                }
     
                // TODO check result == int.MinValue and div = -1
                result = result / div;
            }
        }
     
        return result;
    }
     
    private static int ParseN(string s, ref int pos)
    {
        Contract.Requires(s != null);
        Contract.Requires(pos >= 0);
        Contract.Requires(pos < s.Length);
        Contract.Ensures(pos >= Contract.OldValue(pos));
     
        if (s[pos] == '(')
        {
            pos++;
            TestPosition(s, pos);
            int result = ParseE(s, ref pos);
            if (pos >= s.Length || s[pos] != ')')
            {
                throw new ArgumentException("s");
            }
     
            pos++; // skip ')'
            return result;
        }
     
        if (s[pos] == '-')
        {
            pos++;
            TestPosition(s, pos);
     
            // Todo check -int.MinValue
            return -ParseE(s, ref pos);
        }
     
        if (s[pos] == '+')
        {
            pos++;
            TestPosition(s, pos);
            return ParseE(s, ref pos);
        }
     
        return ParseNumber(s, ref pos);
    }
     
    private static int ParseNumber(string s, ref int pos)
    {
        Contract.Requires(s != null);
        Contract.Requires(pos >= 0);
        Contract.Requires(pos < s.Length);
        Contract.Ensures(pos >= Contract.OldValue(pos));
        Contract.EnsuresOnThrow<ArgumentException>(pos < s.Length && !char.IsNumber(s[pos]));
     
     
        int result = 0;
     
        while (pos < s.Length && char.IsNumber(s[pos]))
        {
            result = (result * 10) + (s[pos] - '0');
            pos++;
        }
     
        return result;
    }
     
    private static void TestPosition(string s, int position)
    {
        Contract.Requires(s != null);
        Contract.Ensures(position >= Contract.OldValue(position));
        Contract.Ensures(position < s.Length);
        Contract.EnsuresOnThrow<ArithmeticException>(position >= s.Length);
     
        if (position >= s.Length)
        {
            throw new ArgumentException("s");
        }
    }

  6. #6
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    Citation Envoyé par Pol63 Voir le message
    le plus simple que j'ai trouvé c'est de passer par du sql
    si tu n'as pas de base de données c'est pas toujours simple mais peut etre bricolable ...

    il suffit alors de exécuter
    "SELECT " + textbox1.text

    et là même si tu te retrouves avec
    (((5+8)/3) +3) *8 ca passe sans se poser de questions
    Au lieu de passer par du sql tu peux faire de la compilation grâce à CodeDom
    http://www.c-sharpcorner.com/uploadf...alculator.aspx

  7. #7
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 37
    Par défaut
    Merci de vos réponses !

    Vu que je fais ca pour le fun, je vais passer par le SQL (très bonne idée), tout en jetant un oeil aux solutions de parsing.

  8. #8
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    Citation Envoyé par meziantou Voir le message
    Au lieu de passer par du sql tu peux faire de la compilation grâce à CodeDom
    http://www.c-sharpcorner.com/uploadf...alculator.aspx
    oui j'ai déjà fait aussi, mais ça reste beaucoup moins performant ...
    0ms en sql et plusieurs dizaines de ms à vu de nez par compilation
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  9. #9
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    oui j'ai déjà fait aussi, mais ça reste beaucoup moins performant ...
    0ms en sql et plusieurs dizaines de ms à vu de nez par compilation
    0ms aussi avec mon parseur

  10. #10
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    surement, m'enfin coder un parseur n'est pas forcément trivial
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  11. #11
    Membre Expert Avatar de meziantou
    Homme Profil pro
    autre
    Inscrit en
    Avril 2010
    Messages
    1 223
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : autre
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2010
    Messages : 1 223
    Par défaut
    surement, m'enfin coder un parseur n'est pas forcément trivia
    Heureusement celui la n'est pas trop compliqué

  12. #12
    Rédacteur
    Avatar de Nathanael Marchand
    Homme Profil pro
    Expert .Net So@t
    Inscrit en
    Octobre 2008
    Messages
    3 615
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Expert .Net So@t
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2008
    Messages : 3 615
    Par défaut
    Sinon tu peux poser l'opération à Google, il sait faire des maths et il te retourne le résultat

  13. #13
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2009
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Février 2009
    Messages : 317
    Par défaut
    Aussi non, si tu n'as toujours pas trouver de solution, tu peux toujours utiliser cette classe, que j'ai déjà utilisé et qui fonctionne relativement bien :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
     
    /// <summary>
    	/// This class is used to convert a string expression to a numeric one, 
    	/// to evaluate this numeric expression and to reconvert the result back
    	/// to string
    	/// </summary>
    	public class FormulaGenerator
    	{
    		#region constructors
    		/// <summary>
    		/// implicit constructor
    		/// </summary>
    		public FormulaGenerator()
    		{
     
    		}//FormulaGenerator
    		#endregion constructors
     
     
    		#region public members
    		public static string EvaluationResult(string astrexpr)
    		{
    			try
    			{
    				if (astrexpr == "") astrexpr = "0";
    				EvalExpr(astrexpr);
    				return m_strservice;
    			}
    			catch(Exception aobjExc)
    			{
                    return "ERROR";
    			}
    		}//EvaluationResult
    		#endregion public members
     
     
    		#region private members
    		//this alghoritm work  for expression with any level of parenthesis 
    		private static void EvalExpr(string astrexpr)
    		{
    			if(ExistParenthesis(astrexpr))
    			{
    				int iposleftparenthesis = PosMaxLevel(astrexpr);
    				string strtemp = astrexpr.Substring(iposleftparenthesis + 1);
    				int iposrightparenthesis = FindFirstChar(strtemp, ')');
    				string strbetweenparenthesis = strtemp.Substring(0, iposrightparenthesis);
     
    				EvalAritm(strbetweenparenthesis.Trim());
     
    				string strbefore = astrexpr.Substring(0,iposleftparenthesis);
    				string strafter = astrexpr.Substring(iposleftparenthesis + iposrightparenthesis + 2);
    				EvalExpr(strbefore + m_strservice + strafter);
    			}
    			else EvalAritm(astrexpr.Trim());
     
    		}//EvalExpr
     
     
    		private static bool ExistParenthesis(string astrexpr)
    		{
    			m_iCharContor = 0;
    			int inbleft = 0;
    			NbOfChar(astrexpr,'(');
    			inbleft = m_iCharContor;
     
    			m_iCharContor = 0;
    			int inbright = 0;
    			NbOfChar(astrexpr, ')');
    			inbright = m_iCharContor;
     
    			if(inbleft != inbright) throw new Exception("Sintax Error!");
    			if (inbleft == 0) return false;
    			return true;
    		}//ExistParenthesis
     
     
    		private static int PosMaxLevel(string astrexpr)
    		{
    			int ipos = -1;
    			int ilevel = 0;
    			int maxlevel = LevelOfParenthesis(astrexpr);
     
    			foreach(char ch in astrexpr.ToCharArray())
    			{
    				ipos+=1;
    				if(ch == '(')
    				{
    					ilevel += 1;
    					if(ilevel == maxlevel)
    					{
    						return ipos;
    					}
    				}
    				else if(ch == ')')
    				{
    					ilevel -= 1;
    				}
    			}
     
    			return 0;
    		}//PosMaxLevel
     
     
     
    		private static int LevelOfParenthesis(string astrexpr)
    		{
    			int ilevel = 0;
    			int ipos = -1;
    			int maxlevel = 0;
    			foreach(char ch in astrexpr.ToCharArray())
    			{
    				ipos += 1;
    				if(ch == '(')
    				{
    					ilevel = ilevel + 1;
    				}
    				else if(ch == ')')
    				{
    					ilevel -= 1;
    				}
    				if(maxlevel < ilevel)
    				{
    					maxlevel = ilevel;
    				}
    			}
    			return maxlevel;
    		}//LevelOfParenthesis
     
     
     
    		private static int FindLastChar(string astrexpr, char acfinder)
    		{
    			return astrexpr.LastIndexOf(acfinder);
    		}//FindLastChar
     
     
    		private static int FindFirstChar(string astrexpr, char acfinder)
    		{
    			return astrexpr.IndexOf(acfinder);
    		}//FindFirstChar
     
     
    		private static int FindSecondChar(string astrexpr, char acfinder)
    		{
    			int ifirst = astrexpr.IndexOf(acfinder);
    			int isecond = astrexpr.Substring(ifirst + 1).IndexOf(acfinder);
    			return ifirst + isecond + 1;
    		}//FindSecondChar
     
     
    		private static void NbOfChar(string astrexpr, char acfinder)
    		{
    			int i = astrexpr.IndexOf(acfinder);
    			if(i >= 0)
    			{
    				m_iCharContor+=1;
    				NbOfChar(astrexpr.Substring(i+1),acfinder);
    			}
    		}//NbOfChar
     
     
    		private static void EvalAritm(string astrexpr)
    		{
    			ProcessPercent(astrexpr);
    			string strwithoutpercent = m_strservice;
     
    			ProcessDivision(strwithoutpercent);
    			string strwithoutdivision = m_strservice;
     
    			ProcessMultiply(strwithoutdivision);
    			string strwithoutmultiply = m_strservice;
     
    			ProcessMinus(strwithoutmultiply);
    			string strwithoutminus = m_strservice;
     
    			ProcessPlus(strwithoutminus);
    			string strwithoutplus = m_strservice;
    		}//EvalAritm
     
     
    		private static void ProcessPercent(string astrexpr)
    		{
    			m_iCharContor = 0;
    			NbOfChar(astrexpr,'%');
    			int inbpercent = m_iCharContor;
     
    			string strnewastrexpr = astrexpr.Trim();
    			m_iCharContor = 0;
    			NbOfChar(strnewastrexpr, '%');
    			if(m_iCharContor == 0)
    			{
    				m_strservice = strnewastrexpr;
    			}
    			if(inbpercent > 0)
    			{
    				string astrexprwithoutbreak = astrexpr.Trim();
    				int ipospercent = FindFirstChar(astrexprwithoutbreak,'%');
    				string astrwithoutpercent;
    				if (ipospercent >= 1)
    				{
    					astrwithoutpercent = astrexprwithoutbreak.Substring(0,ipospercent);
    				}
    				else
    				{
    					throw new Exception("Sintax error!");
    				}
     
    				int ilastdivision = FindLastChar(astrwithoutpercent,'/');
    				int ilastmultiply = FindLastChar(astrwithoutpercent,'*');
    				int ilastminus = FindLastChar(astrwithoutpercent,'-');
    				int ilastplus = FindLastChar(astrwithoutpercent,'+');
     
     
    				ArrayList arlsigns = new ArrayList();
    				arlsigns.Add(ilastdivision);
    				arlsigns.Add(ilastmultiply);
    				arlsigns.Add(ilastminus);
    				arlsigns.Add(ilastplus);
    				int imaxsignpos = NbMax(arlsigns);
    				if(imaxsignpos < 0) imaxsignpos = 0;
     
    				string strpercent;
    				string strbeforepercent;
    				if(imaxsignpos >= 1)
    				{
    					strpercent = astrwithoutpercent.Substring(imaxsignpos + 1).Trim();
    					strbeforepercent = astrwithoutpercent.Substring(0,imaxsignpos+1).Trim();
    				}
    				else
    				{
    					strpercent = astrwithoutpercent.Trim();
    					strbeforepercent = "";
    				}
     
    				string strafterpercent="";
    				if(ipospercent < astrexprwithoutbreak.Length - 1) 
    				{
    					strafterpercent = astrexprwithoutbreak.Substring(ipospercent+1).Trim();
    				}
     
    				decimal dpercentvalue = ConvertToValue(strpercent);
    				strnewastrexpr = strbeforepercent + Convert.ToString(dpercentvalue) + strafterpercent;
    				ProcessPercent(strnewastrexpr);
    			}
    		}//ProcessPercent
     
     
    		private static void ProcessDivision(string astrexpr)
    		{
    			m_iCharContor = 0;
    			NbOfChar(astrexpr,'/');
    			int inbdivision = m_iCharContor;
     
    			string strnewastrexpr = astrexpr.Trim();
    			m_iCharContor = 0;
    			NbOfChar(strnewastrexpr, '/');
    			if(m_iCharContor == 0)
    			{
    				m_strservice = strnewastrexpr;
    			}
     
    			if(inbdivision > 0)
    			{
    				string astrexprwithoutbreak = astrexpr.Trim();
    				int iposdivision = FindFirstChar(astrexprwithoutbreak,'/');
    				string astrbeforedivision;
    				if (iposdivision >= 1)
    				{
    					astrbeforedivision = astrexprwithoutbreak.Substring(0,iposdivision).Trim();
    				}
    				else
    				{
    					throw new Exception("Division error!");
    				}
     
    				string astrafterdivision;
    				if(iposdivision < astrexprwithoutbreak.Length - 1)
    				{
    					astrafterdivision = astrexprwithoutbreak.Substring(iposdivision + 1).Trim();
    				}
    				else
    				{
    					throw new Exception("Division error!");
    				}
     
    				int ilastdivisionbefore = FindLastChar(astrbeforedivision,'/');
    				int ilastmultiplybefore = FindLastChar(astrbeforedivision,'*');
    				int ilastminusbefore = FindLastChar(astrbeforedivision,'-');
    				int ilastplusbefore = FindLastChar(astrbeforedivision,'+');
     
    				int ilastdivisionafter = FindFirstChar(astrafterdivision,'/');
    				int ilastmultiplyafter = FindFirstChar(astrafterdivision,'*');
    				int ilastminusafter = FindFirstChar(astrafterdivision,'-');
    				int ilastplusafter = FindFirstChar(astrafterdivision,'+');
     
    				ArrayList arlsignsbefore = new ArrayList();
    				arlsignsbefore.Add(ilastdivisionbefore);
    				arlsignsbefore.Add(ilastmultiplybefore);
    				arlsignsbefore.Add(ilastminusbefore);
    				arlsignsbefore.Add(ilastplusbefore);
    				int imaxsignpos = NbMax(arlsignsbefore);
    				if (imaxsignpos <= 0) imaxsignpos = -1;
     
    				ArrayList arlsignsafter = new ArrayList();
    				arlsignsafter.Add(ilastdivisionafter);
    				arlsignsafter.Add(ilastmultiplyafter);
    				arlsignsafter.Add(ilastminusafter);
    				arlsignsafter.Add(ilastplusafter);
    				int iminsignpos = NbMin(arlsignsafter);
    				if (iminsignpos <= 0) iminsignpos = 0; 
     
    				string strbeforedivisionafter = astrbeforedivision.Substring(imaxsignpos + 1).Trim();
    				string strbeforedivisionbefore = astrbeforedivision.Substring(0,imaxsignpos + 1).Trim();
     
    				string strafterdivisionbefore = astrafterdivision.Substring(0,iminsignpos).Trim();
    				string strafterdivisionafter = astrafterdivision.Substring(iminsignpos).Trim();
     
    				bool issignbefore = false;
    				if(strbeforedivisionbefore.Length > 0)
    				{
    					if(strbeforedivisionbefore.Substring(0,1).Trim() == "-")
    					{
    						issignbefore = true;
    					}
    				}
     
    				bool issignafter = false;
    				if(strafterdivisionbefore.Length > 0)
    				{
    					if(strafterdivisionbefore.Substring(0,1).Trim() == "-")
    					{
    						issignafter = true;
    					}
    				}
     
    				decimal dbeforedivision;
    				if(strbeforedivisionafter.Length > 0)
    				{
    					dbeforedivision = Convert.ToDecimal(SetDecimalSeparator(strbeforedivisionafter));
    				}
    				else if(strbeforedivisionbefore.Length > 0)
    				{
    					dbeforedivision = Convert.ToDecimal(SetDecimalSeparator(strbeforedivisionbefore));
    				}
    				else dbeforedivision = 0;
     
    				decimal dafterdivision;
    				if(strafterdivisionbefore.Length > 0)
    				{
    					dafterdivision = Convert.ToDecimal(SetDecimalSeparator(strafterdivisionbefore));
    				}
    				else if(strafterdivisionafter.Length > 0)
    				{
    					dafterdivision = Convert.ToDecimal(SetDecimalSeparator(strafterdivisionafter));
    				}
    				else dafterdivision = 1;
     
    				decimal ddivision=0;
    				if(dafterdivision != 0)
    				{
    					if(issignbefore || issignafter)
    					{
    						ddivision = (-1) * dbeforedivision / dafterdivision;
    					}
    					else ddivision = dbeforedivision / dafterdivision;
    				}
     
    				strnewastrexpr = strbeforedivisionbefore + Convert.ToString(ddivision) + strafterdivisionafter;
    				if(strafterdivisionbefore == "") strnewastrexpr = strbeforedivisionbefore + Convert.ToString(ddivision);
    				ProcessDivision(strnewastrexpr);
    			}
    		}//ProcessDivision
     
     
     
    		private static void ProcessMultiply(string astrexpr)
    		{
    			m_iCharContor = 0;
    			NbOfChar(astrexpr,'*');
    			int inbmultiply = m_iCharContor;
     
    			string strnewastrexpr = astrexpr.Trim();
    			m_iCharContor = 0;
    			NbOfChar(strnewastrexpr, '*');
    			if(m_iCharContor == 0)
    			{
    				m_strservice = strnewastrexpr;
    			}
     
    			if(inbmultiply > 0)
    			{
    				string astrexprwithoutbreak = astrexpr.Trim();
    				int iposmultiply = FindFirstChar(astrexprwithoutbreak,'*');
    				string astrbeforemultiply;
    				if (iposmultiply >= 1)
    				{
    					astrbeforemultiply = astrexprwithoutbreak.Substring(0,iposmultiply).Trim();
    				}
    				else
    				{
    					throw new Exception("Error!");
    				}
     
    				string astraftermultiply;
    				if(iposmultiply < astrexprwithoutbreak.Length - 1)
    				{
    					astraftermultiply = astrexprwithoutbreak.Substring(iposmultiply + 1).Trim();
    				}
    				else
    				{
    					throw new Exception("Error!");
    				}
     
    				int ilastdivisionbefore = FindLastChar(astrbeforemultiply,'/');
    				int ilastmultiplybefore = FindLastChar(astrbeforemultiply,'*');
    				int ilastminusbefore = FindLastChar(astrbeforemultiply,'-');
    				int ilastplusbefore = FindLastChar(astrbeforemultiply,'+');
     
    				int ilastdivisionafter = FindFirstChar(astraftermultiply,'/');
    				int ilastmultiplyafter = FindFirstChar(astraftermultiply,'*');
    				int ilastminusafter = FindFirstChar(astraftermultiply,'-');
    				int ilastplusafter = FindFirstChar(astraftermultiply,'+');
     
    				ArrayList arlsignsbefore = new ArrayList();
    				arlsignsbefore.Add(ilastdivisionbefore);
    				arlsignsbefore.Add(ilastmultiplybefore);
    				arlsignsbefore.Add(ilastminusbefore);
    				arlsignsbefore.Add(ilastplusbefore);
    				int imaxsignpos = NbMax(arlsignsbefore);
    				if (imaxsignpos <= 0) imaxsignpos = -1;
     
    				ArrayList arlsignsafter = new ArrayList();
    				arlsignsafter.Add(ilastdivisionafter);
    				arlsignsafter.Add(ilastmultiplyafter);
    				arlsignsafter.Add(ilastminusafter);
    				arlsignsafter.Add(ilastplusafter);
    				int iminsignpos = NbMin(arlsignsafter);
    				if (iminsignpos <= 0) iminsignpos = 0; 
     
    				string strbeforemultiplyafter = astrbeforemultiply.Substring(imaxsignpos + 1).Trim();
    				string strbeforemultiplybefore = astrbeforemultiply.Substring(0,imaxsignpos + 1).Trim();
     
    				string straftermultiplybefore = astraftermultiply.Substring(0,iminsignpos).Trim();
    				string straftermultiplyafter = astraftermultiply.Substring(iminsignpos).Trim();
     
    				bool issignbefore = false;
    				if(strbeforemultiplybefore.Length > 0)
    				{
    					if(strbeforemultiplybefore.Substring(0,1).Trim() == "-")
    					{
    						//issignbefore = true;
    					}
    				}
     
    				bool issignafter = false;
    				if(straftermultiplybefore.Length > 0)
    				{
    					if(straftermultiplybefore.Substring(0,1).Trim() == "-")
    					{
    						issignafter = true;
    					}
    				}
     
    				decimal dbeforemultiply;
    				if(strbeforemultiplyafter.Length > 0)
    				{
    					if(IsDigit(strbeforemultiplyafter) == true)
    					{
    						dbeforemultiply = Convert.ToDecimal(SetDecimalSeparator(strbeforemultiplyafter));
    					}
    					else
    					{
    						dbeforemultiply = ConvertToValue(strbeforemultiplyafter);
    					}
    				}
    				else if(strbeforemultiplybefore.Length > 0)
    				{
    					if(IsDigit(strbeforemultiplybefore) == true)
    					{
    						dbeforemultiply = Convert.ToDecimal(SetDecimalSeparator(strbeforemultiplybefore));
    					}
    					else
    					{
    						dbeforemultiply = ConvertToValue(strbeforemultiplybefore);
    					}
    				}
    				else dbeforemultiply = 0;
     
    				decimal daftermultiply;
    				if(straftermultiplybefore.Length > 0)
    				{
    					if(IsDigit(straftermultiplybefore) == true)
    					{
    						daftermultiply = Convert.ToDecimal(SetDecimalSeparator(straftermultiplybefore));
    					}
    					else
    					{
    						daftermultiply = ConvertToValue(straftermultiplybefore);
    					}
    				}
    				else if(straftermultiplyafter.Length > 0)
    				{
    					if(IsDigit(straftermultiplyafter) == true)
    					{
    						daftermultiply = Convert.ToDecimal(SetDecimalSeparator(straftermultiplyafter));
    					}
    					else
    					{
    						daftermultiply = ConvertToValue(straftermultiplyafter);
    					}
    				}
    				else daftermultiply = 0;
     
    				decimal dmultiply=0;
    				if(daftermultiply != 0)
    				{
    					if(issignbefore || issignafter)
    					{
    						dmultiply = (-1) * dbeforemultiply * daftermultiply;
    					}
    					else dmultiply = dbeforemultiply * daftermultiply;
    				}
     
    				strnewastrexpr = strbeforemultiplybefore + Convert.ToString(dmultiply) + straftermultiplyafter;
    				if(straftermultiplybefore == "") strnewastrexpr = strbeforemultiplybefore + Convert.ToString(dmultiply);
    				ProcessMultiply(strnewastrexpr);
    			}
    		}//ProcessMultiply
     
     
    		private static void ProcessMinus(string astrexpr)
    		{
    			m_iCharContor = 0;
    			NbOfChar(astrexpr,'-');
     
    			int iposminustest = FindFirstChar(astrexpr.Trim(),'-');
    			//if(iposminustest == 0) iposminustest = this.FindSecondChar(astrexpr.Trim(),'-');
     
    			string strnewastrexpr = astrexpr.Trim();
    			m_iCharContor = 0;
    			NbOfChar(strnewastrexpr, '-');
    			if(iposminustest == 0)m_iCharContor -= 1;
    			int inbminus = m_iCharContor;
    			if(m_iCharContor == 0)
    			{
    				m_strservice = strnewastrexpr;
    			}
     
    			if(inbminus > 0)
    			{
    				string astrexprwithoutbreak = astrexpr.Trim();
    				//if(iposminustest == 0) astrexprwithoutbreak = astrexprwithoutbreak.Substring(1);
    				int iposminus = FindFirstChar(astrexprwithoutbreak,'-');
    				if (iposminus == 0)iposminus = FindSecondChar(astrexprwithoutbreak,'-'); 
    				string astrbeforeminus;
    				if (iposminus >= 1)
    				{
    					astrbeforeminus = astrexprwithoutbreak.Substring(0,iposminus).Trim();
    				}
    				else
    				{
    					astrbeforeminus = astrexprwithoutbreak.Substring(0,iposminus).Trim();
    				}
     
    				string astrafterminus;
    				if(iposminus < astrexprwithoutbreak.Length - 1)
    				{
    					astrafterminus = astrexprwithoutbreak.Substring(iposminus + 1).Trim();
    					//if(iposminustest == 0)astrafterminus = astrafterminus.Substring(1).Trim();
    				}
    				else
    				{
    					throw new Exception("Error!");
    				}
     
    				int ilastdivisionbefore = FindLastChar(astrbeforeminus,'/');
    				int ilastmultiplybefore = FindLastChar(astrbeforeminus,'*');
    				int ilastminusbefore = FindLastChar(astrbeforeminus,'-');
    				int ilastplusbefore = FindLastChar(astrbeforeminus,'+');
     
    				int ilastdivisionafter = FindFirstChar(astrafterminus,'/');
    				int ilastmultiplyafter = FindFirstChar(astrafterminus,'*');
    				int ilastminusafter = FindFirstChar(astrafterminus,'-');
    				int ilastplusafter = FindFirstChar(astrafterminus,'+');
     
    				ArrayList arlsignsbefore = new ArrayList();
    				arlsignsbefore.Add(ilastdivisionbefore);
    				arlsignsbefore.Add(ilastmultiplybefore);
    				arlsignsbefore.Add(ilastminusbefore);
    				arlsignsbefore.Add(ilastplusbefore);
    				int imaxsignpos = NbMax(arlsignsbefore);
    				if (imaxsignpos <= 0) imaxsignpos = -1;
     
    				ArrayList arlsignsafter = new ArrayList();
    				arlsignsafter.Add(ilastdivisionafter);
    				arlsignsafter.Add(ilastmultiplyafter);
    				arlsignsafter.Add(ilastminusafter);
    				arlsignsafter.Add(ilastplusafter);
    				int iminsignpos = NbMin(arlsignsafter);
    				if (iminsignpos <= 0) iminsignpos = 0; 
     
    				string strbeforeminusafter = astrbeforeminus.Substring(imaxsignpos + 1).Trim();
    				string strbeforeminusbefore = astrbeforeminus.Substring(0,imaxsignpos + 1).Trim();
     
    				string strafterminusbefore = astrafterminus.Substring(0,iminsignpos).Trim();
    				string strafterminusafter = astrafterminus.Substring(iminsignpos).Trim();
     
    				decimal dbeforeminus = 0;
    				if(strbeforeminusafter.Length > 0)
    				{
    					if(IsDigit(strbeforeminusafter) == true)
    					{
    						dbeforeminus = Convert.ToDecimal(SetDecimalSeparator(strbeforeminusafter));
    					}
    					else
    					{
    						dbeforeminus = ConvertToValue(strbeforeminusafter);
    					}
    				}
    				else if(strbeforeminusbefore.Length > 0)
    				{
    					if(IsDigit(strbeforeminusbefore) == true)
    					{
    						dbeforeminus = Convert.ToDecimal(SetDecimalSeparator(strbeforeminusbefore));
    					}
    					else
    					{
    						dbeforeminus = ConvertToValue(strbeforeminusbefore);
    					}
    				}
     
    				decimal dafterminus = 0;
    				if(strafterminusbefore.Length > 0)
    				{
    					if(IsDigit(strafterminusbefore))
    					{
    						dafterminus = Convert.ToDecimal(SetDecimalSeparator(strafterminusbefore));
    					}
    					else
    					{
    						dafterminus = ConvertToValue(strafterminusbefore);
    					}
    				}
    				else if(strafterminusafter.Length > 0)
    				{
    					if(IsDigit(strafterminusafter))
    					{
    						dafterminus = Convert.ToDecimal(SetDecimalSeparator(strafterminusafter));
    					}
    					else
    					{
    						dafterminus = ConvertToValue(strafterminusafter);
    					}
    				}
     
    				decimal dminus=0;
    				dminus = dbeforeminus - dafterminus;
     
    				strnewastrexpr = strbeforeminusbefore + Convert.ToString(dminus) + strafterminusafter;
    				if(strafterminusbefore == "") strnewastrexpr = strbeforeminusbefore + Convert.ToString(dminus);
     
    				ProcessMinus(strnewastrexpr);
    			}
    		}//ProcessMinus
     
     
    		private static void ProcessPlus(string astrexpr)
    		{
    			m_iCharContor = 0;
    			NbOfChar(astrexpr,'+');
    			int inbplus = m_iCharContor;
     
    			string strnewastrexpr = astrexpr.Trim();
    			m_iCharContor = 0;
    			NbOfChar(strnewastrexpr, '+');
    			if(m_iCharContor == 0)
    			{
    				m_strservice = strnewastrexpr;
    			}
     
    			if(inbplus > 0)
    			{
    				string astrexprwithoutbreak = astrexpr.Trim();
    				int iposplus = FindFirstChar(astrexprwithoutbreak,'+');
    				string astrbeforeplus;
    				if (iposplus >= 1)
    				{
    					astrbeforeplus = astrexprwithoutbreak.Substring(0,iposplus).Trim();
    				}
    				else
    				{
    					throw new Exception("Error!");
    				}
     
    				string astrafterplus;
    				if(iposplus < astrexprwithoutbreak.Length - 1)
    				{
    					astrafterplus = astrexprwithoutbreak.Substring(iposplus + 1).Trim();
    				}
    				else
    				{
    					throw new Exception("Error!");
    				}
     
    				int ilastdivisionbefore = FindLastChar(astrbeforeplus,'/');
    				int ilastmultiplybefore = FindLastChar(astrbeforeplus,'*');
    				int ilastminusbefore = FindLastChar(astrbeforeplus,'-');
    				int ilastplusbefore = FindLastChar(astrbeforeplus,'+');
     
    				int ilastdivisionafter = FindFirstChar(astrafterplus,'/');
    				int ilastmultiplyafter = FindFirstChar(astrafterplus,'*');
    				int ilastminusafter = FindFirstChar(astrafterplus,'-');
    				int ilastplusafter = FindFirstChar(astrafterplus,'+');
     
    				ArrayList arlsignsbefore = new ArrayList();
    				arlsignsbefore.Add(ilastdivisionbefore);
    				arlsignsbefore.Add(ilastmultiplybefore);
    				arlsignsbefore.Add(ilastminusbefore);
    				arlsignsbefore.Add(ilastplusbefore);
    				int imaxsignpos = NbMax(arlsignsbefore);
    				if (imaxsignpos <= 0) imaxsignpos = -1;
     
    				ArrayList arlsignsafter = new ArrayList();
    				arlsignsafter.Add(ilastdivisionafter);
    				arlsignsafter.Add(ilastmultiplyafter);
    				arlsignsafter.Add(ilastminusafter);
    				arlsignsafter.Add(ilastplusafter);
    				int iminsignpos = NbMin(arlsignsafter);
    				if (iminsignpos <= 0) iminsignpos = 0; 
     
    				string strbeforeplusafter = astrbeforeplus.Substring(imaxsignpos + 1).Trim();
    				string strbeforeplusbefore = astrbeforeplus.Substring(0,imaxsignpos + 1).Trim();
     
    				string strafterplusbefore = astrafterplus.Substring(0,iminsignpos).Trim();
    				string strafterplusafter = astrafterplus.Substring(iminsignpos).Trim();
     
    				decimal dbeforeplus = 0;
    				if(strbeforeplusafter.Length > 0)
    				{
    					if(IsDigit(strbeforeplusafter) == true)
    					{
    						dbeforeplus = Convert.ToDecimal(SetDecimalSeparator(strbeforeplusafter));
    					}
    					else
    					{
    						dbeforeplus = ConvertToValue(strbeforeplusafter);
    					}
    				}
    				else if(strbeforeplusbefore.Length > 0)
    				{
    					if(IsDigit(strbeforeplusbefore) == true)
    					{
    						dbeforeplus = Convert.ToDecimal(SetDecimalSeparator(strbeforeplusbefore));
    					}
    					else
    					{
    						dbeforeplus = ConvertToValue(strbeforeplusbefore);
    					}
    				}
     
     
    				decimal dafterplus = 0;
    				if(strafterplusbefore.Length > 0)
    				{
    					if(IsDigit(strafterplusbefore) == true)
    					{
    						dafterplus = Convert.ToDecimal(SetDecimalSeparator(strafterplusbefore));
    					}
    					else
    					{
    						dafterplus = ConvertToValue(strafterplusbefore);
    					}
    				}
    				else if(strafterplusafter.Length > 0)
    				{
    					if(IsDigit(strafterplusafter) == true)
    					{
    						dafterplus = Convert.ToDecimal(SetDecimalSeparator(strafterplusafter));
    					}
    					else
    					{
    						dafterplus = ConvertToValue(strafterplusafter);
    					}
    				}
     
     
    				decimal dplus=0;
    				dplus = dbeforeplus + dafterplus;
     
    				strnewastrexpr = strbeforeplusbefore + Convert.ToString(dplus) + strafterplusafter;
    				if(strafterplusbefore == "") strnewastrexpr = strbeforeplusbefore + Convert.ToString(dplus);
    				ProcessPlus(strnewastrexpr);
    			}
    			else
    			{
    				if(IsDigit(astrexpr) == false)
    				{
    					ConvertToValue(astrexpr);
    				}
    			}
    		}//ProcessPlus
     
     
    		private static decimal ConvertToValue(string astrexpr)
    		{
     
    			bool bmarker = true;
    			decimal dexpr = 0;
    			for(int i=0;i <= astrexpr.Length - 1;i++)
    			{
    				string strlocal = astrexpr.Substring(i,1);
    				if ((i != 0) || (strlocal != "-"))
    				{
    					char[] ch = strlocal.ToCharArray();
    					if((Char.IsDigit(ch[0]) == false) && (strlocal != ".") && (strlocal != ",") /*&& (strlocal != " ")*/)
    					{
    						bmarker = false;
    					}
    				}
    			}
     
    			if(bmarker == true)
    			{
    				dexpr = Convert.ToDecimal(astrexpr)/100;
    			}
    			else
    			{
     
    				throw new Exception("Not numeric value!");
    			}
     
    			return dexpr;
    		}//ConvertToValue
     
     
    		private static int NbMax(ArrayList aobjarl)
    		{
    			int max = 0;
    			foreach(object obj in aobjarl)
    			{
    				if((int)obj != -1)
    				{
    					if(max <= (int)obj) max = (int)obj;
    				}
    			}
    			return max;
    		}//NbMax
     
     
    		private static int NbMin(ArrayList aobjarl)
    		{
    			int min = NbMax(aobjarl);
    			foreach(object obj in aobjarl)
    			{
    				if((int)obj != -1)
    				{
    					if(min >= (int)obj) min = (int)obj;
    				}
    			}
    			return min;
    		}//NbMin
     
     
    		private static bool IsDigit(string astrexpr)
    		{
    			foreach(char ch in astrexpr.ToCharArray())
    			{
    				if((ch != '-')&&(ch != ' ')&&(ch != '.')&&(ch != ','))
    				{
    					if (Char.IsDigit(ch) == false)
    					{
    						return false;
    					}
    				}
    			}
    			return true;
    		}//IsDigit
     
     
    		private static string SetDecimalSeparator(string astrexpr)
    		{
    			string strseparator = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
    			int ipoint = astrexpr.IndexOf('.');
    			int icomma = astrexpr.IndexOf(',');
    			string newastrexpr;
     
    			if(ipoint >= 0)
    			{
    				newastrexpr = astrexpr.Replace(".",strseparator);
    			}
    			else if(icomma >= 0)
    			{
    				newastrexpr = astrexpr.Replace(",",strseparator);
    			}
    			else
    			{
    				newastrexpr = astrexpr;
    			}
    			return newastrexpr;
    		}//SetDecimalSeparator
     
     
    		private static int m_iCharContor = 0;
    		private static string m_strservice = "";
    		private static double m_iNbOfMinus = 0;
    		private static string m_strExpression;
     
     
     
    		#endregion private members
     
     
     
     
     
    	}

Discussions similaires

  1. Développement d'une calculatrice en swing
    Par alexlevenere dans le forum Agents de placement/Fenêtres
    Réponses: 3
    Dernier message: 29/07/2014, 13h17
  2. Développement d'une calculatrice
    Par perrotta dans le forum Tcl/Tk
    Réponses: 1
    Dernier message: 21/07/2009, 23h01
  3. [D7] Développement d'une interface HL7
    Par Stef_D dans le forum Composants VCL
    Réponses: 8
    Dernier message: 05/08/2008, 17h21
  4. Développement d'une calculatrice
    Par tatemilio2 dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 12/10/2006, 19h21
  5. Développement d'une application multi-sites ?
    Par ChrisPM dans le forum Architecture
    Réponses: 7
    Dernier message: 09/11/2005, 14h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo