New topic: 

Fonction Validation Formule Mathématique

<http://forums.realsoftware.com/viewtopic.php?t=46026>

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        O-Matic          Post subject: Fonction Validation Formule 
MathématiquePosted: Thu Nov 22, 2012 11:12 pm                         
Joined: Mon Apr 30, 2012 9:57 pm
Posts: 5                Bonjour, voici une fonction qui valide (boolean) une 
formule mathématique (string).
Exemple: ((1.25+24)*(6.625-1.25/2)+5)-4.5
Résultat: True

Que pensez-vous de ma fonction... c'est bon? c'est mauvais?. Pourquoi!  Vos 
commentaires SVP.

Function FormuleValide(formule As String) As Boolean
  Dim valide As Boolean = False
  formule = formule.Trim
  If formule <> "" Then
  'Initialisation
  Dim i, long, pa, pt As Integer
  Dim c1, c2 As String
  pa = 0
  pt = 0
  'Validation du premier caractère
  c1 = formule.Mid(1,1)
  If InStr("0123456789-(", c1) > 0 Then
  'Validation des caractères centre
  valide = True 'Anticipation
  long = formule.Len
  For i = 1 To long - 1
    c1 = formule.Mid(i,1)
    c2 = formule.Mid(i+1,1)
    If c1 >= "0" And c1 <= "9" Then
    If InStr("0123456789+-*/).", c2) = 0 Then valide = False
    Elseif c1 = "+" Or c1 = "-" Then
    pt = 0
    If InStr("0123456789(", c2) = 0 Then valide = False
    Elseif c1 = "*" Or c1 = "/" Then
    pt = 0
    If InStr("0123456789-(", c2) = 0 Then valide = False
    Elseif c1 = "(" Then
    pa = pa + 1
    If InStr("0123456789-(", c2) = 0 Then valide = False
    Elseif c1 = ")" Then
    pa = pa - 1
    If InStr("+-*/)", c2) = 0 Then valide = False
    Elseif c1 = "." Then
    pt = pt + 1
    If InStr("0123456789", c2) = 0 Then valide = False
    End
    'Validation point
    If pt > 1 Then valide = False
  Next
  'Validation dernier caractère
  If long > 1 Then
    c2 = formule.Mid(long,1)
    If c2 = ")" Then pa = pa - 1
    If InStr("+-*/(.", c2) > 0 Then valide = False
  End
  'Validation parenthèse
  If pa <> 0 Then valide = False
  End
  End
  Return valide
End Function
   
                             Top                Akiland          Post subject: 
Re: Fonction Validation Formule MathématiquePosted: Fri Nov 23, 2012 12:18 am  
                               
Joined: Tue Jan 04, 2011 3:02 am
Posts: 1020
Location: Jönköping, Sweden                Google translation:
Quote:Hello, here is a function that validates (boolean) a mathematical formula 
(string).
Example: ((1.25 +24) * (6.625-1.25 / 2) +5) -4.5
Result: True

What do you think of my job ... is it good? this is bad?. Why! Your feedback.
      
_________________
 http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
REAL.Studio Web Edition 2011r3  
                             Top                DaveS          Post subject: 
Re: Fonction Validation Formule MathématiquePosted: Fri Nov 23, 2012 12:23 am  
                               
Joined: Sun Aug 05, 2007 10:46 am
Posts: 4292
Location: San Diego, CA                You will get more feedback if you can 
post in English
Vous obtiendrez plus d'informations si vous pouvez poster en anglais
Google Translate can help
Google Translate peut vous aider


Quote:Hello, here is a function that validates (boolean) a mathematical formula 
(string).
Example: ((1.25 +24) * (6.625-1.25 / 2) +5) -4.5
Result: True

What do you think of my job ... is it good? this is bad?. Why! Your feedback.
      
_________________
Dave Sisemore
MacPro, OSX Lion 10.7.4 RB2012r1
Note : I am not  interested in any solutions that involve custom Plug-ins of 
any kind  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to