P. 1
operacio

operacio

|Views: 2|Likes:
Published by Joan Jimenez Jané

More info:

Published by: Joan Jimenez Jané on Oct 29, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

10/29/2011

pdf

text

original

Function opera_parentesi_mes_intern(ByVal operInd As String, ByVal valors() As I nt32, ByRef qt As Int32, ByRef nError As Int32) As String Dim

numParen, cont, i, q, res As Int32 Dim nouCadena, cadOper As String Dim esMult As Boolean numParen = 0 i = 0 q = 0 While i < operInd.Length If operInd.Chars(i) = "(" Then numParen = numParen + 1 End If i = i + 1 End While i = 0 'bucle per agafar on comença lultim parentesi mes intern While q < numParen If operInd.Chars(i) = "(" Then q = q + 1 End If i = i + 1 End While q = i While q < operInd.Length AndAlso operInd.Chars(q) <> ")" q = q + 1 End While cadOper = operInd.Substring(i, q - i) nouCadena = operInd.Substring(0, i) cont = 0 While cont < cadOper.Length If cadOper.Chars(cont) = "*" Then res = valors(Int32.Parse(cadOper(cont - 1)) - 1) * valors(Int32. Parse(cadOper(cont + 1)) - 1) valors(Int32.Parse(cadOper(cont + 1)) - 1) = res If esMult = True Then nouCadena = nouCadena.Substring(0, nouCadena.Length - 1) & c adOper(cont + 1) Else nouCadena = nouCadena & cadOper(cont + 1) End If

Chars(cont + 2) Like "[*/]" Then nouCadena = nouCadena & cadOper(cont .Parse(cadOper(cont + 1)) .1) valors(Int32.Parse(cadOper(cont + 1)) .1) valors(Int32.1)) .Chars(cont) = "-" OrElse cadOper.Chars(cont) = "+" Th en esMult = False If cont + 2 < cadOper.Parse(cadOper(cont .1)) .1) & cadOper(cont ) Else If cadOper.1) = res If nouCadena.Parse(cadOper(cont + 1)) .Substring(0.Chars(cont) = "+" Then res = valors(Int32.Parse(cadOper(cont + 1)) .Parse(cadOper(cont .1) + v alors(Int32.Parse(cadOper(cont + 1)) . nouCadena.Parse(cadOper(cont + 1)) .1) = res nouCadena = nouCadena & cadOper(cont + 1) cont = cont + 1 End If End If Else If cadOper.1) / valors(Int32 .1)) .1)) .Parse(cadOper(cont + 1)) .1) = res 'nouCadena = nouCadena & cadOper(cont + 1) esMult = False ElseIf cadOper.v alors(Int32.esMult = True ElseIf cadOper.Length .1 < 0 Then nouCadena = cadOper(cont + 1) Else nouCadena = nouCadena.Parse(cadOper(cont .1) valors(Int32.1) 'valors(Int32.1) = res nouCadena = nouCadena & cadOper(cont + 1) cont = cont + 1 Else res = valors(Int32.Length .1) & cadOper(cont + 1) End If cont = cont + 1 Else .1) .1) + valor s(Int32.Chars(cont) = "+" Then res = valors(Int32.Parse(cadOper(cont + 1)) .Chars(cont) = "/" Then 'res = valors(Int32.Length Then If cadOper.Parse(cadOper(cont .

operInd.Parse(cadOper(cont .valor s(Int32.1) . nouCadena.Parse(cadOper(cont + 1)) .1 < 0 Then nouCadena = cadOper(cont + 1) Else nouCadena = nouCadena.1) valors(Int32.Length > 2 Then nError = 1 Else nError = 0 End If Return nouCadena End Function .Chars(i .Substring(q.Parse(cadOper(cont + 1)) .res = valors(Int32.Substring(0.Length .1) = res If nouCadena.1) = "(" Then nouCadena = nouCadena & operInd.Length .Length .1) & cadOper(cont + 1) End If cont = cont + 1 End If End If End If cont = cont + 1 End While If i .1 >= 0 Then If nouCadena.q) End If End If 'en aquesta funcio mirem que no ens quedi un resultat com (2) nouCadena = treureParentesi(nouCadena) If nouCadena.1)) .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->