elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Sacar numeros de una ecuacion? reto?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Sacar numeros de una ecuacion? reto?  (Leído 4,793 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Sacar numeros de una ecuacion? reto?
« Respuesta #10 en: 12 Marzo 2011, 20:06 pm »

.
@XXX-ZERO-XXX

No se si esto que estoy haciendo te ayude (Lo estoy haciendo para tratar Despejes):

Código
  1.  
  2. '
  3. ' ////////////////////////////////////////////////////////////////
  4. ' // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
  5. ' //                                                            //
  6. ' // Web: http://InfrAngeluX.Sytes.Net/                         //
  7. ' //                                                            //
  8. ' // |-> Pueden Distribuir Este Código siempre y cuando         //
  9. ' // no se eliminen los créditos originales de este código      //
  10. ' // No importando que sea modificado/editado o engrandecido    //
  11. ' // o achicado, si es en base a este código                    //
  12. ' ////////////////////////////////////////////////////////////////
  13. ' //
  14. ' ////////////////////////////////////////////////////////////////
  15.  
  16. ' 50x-9+114-32x
  17. ' (50-32)x = 9-114
  18. ' x = (9-114) / (50-32)
  19.  
  20. Option Explicit
  21.  
  22. Enum eOperandos
  23.    eParentesisI = 0
  24.    eParentesisF = 1
  25.    ePotencia = 2
  26.    eRaiz = 3
  27.    eMultiplicacion = 4
  28.    eDivicion = 5
  29.    eSuma = 6
  30.    eResta = 7
  31. End Enum
  32.  
  33. Private Operandos(0 To 7) As String
  34.  
  35. '   //  Ecuación de 1er grado.
  36. 'Public Function EcuacionLineal(ByVal vExpresion$) As String'
  37. 'Dim str_Exp$()
  38. '    str_expr$() = Split(vExpresion$, "=", 2)'
  39. '    If UBound(str_expr$) = 1 Then
  40. '        ReDim Preserve str_expr$(0 To 1)
  41. '    End If
  42.    '   //  Hubicamos los terminos (Incognitas en el lado izquierdo y las constantes en el derecho)
  43.  
  44. 'End Function
  45.  
  46. Public Function GetParentesis(ByVal vExpresion$) As String
  47. Dim lng_op&(0 To 1)             '   //  Posicion Inicial/Final
  48. Dim str_bloq$
  49. Dim boo_res         As Boolean
  50.  
  51.    lng_op&(1) = InStr(1, vExpresion$, Operandos(eOperandos.eParentesisF))
  52.    If (lng_op&(1) <> 0) Then
  53.        lng_op&(0) = InStrRev(vExpresion$, Operandos(eOperandos.eParentesisI), lng_op&(1))
  54.        If (lng_op&(0) = 0) Then
  55.            lng_op&(0) = 1
  56.        Else
  57.            lng_op&(0) = lng_op&(0) + 1
  58.        End If
  59.        GetParentesis = Mid$(vExpresion$, lng_op&(0), lng_op&(1) - lng_op&(0))
  60.    Else
  61.        GetParentesis = vExpresion$
  62.    End If
  63.  
  64. End Function
  65.  
  66.  
  67. ' // Terminos Semejantes ( Con incognita ).
  68. Public Function ReduccionDeOperandos(ByVal vExpresion$, Optional ByVal Incognita As String = "x") As String
  69. Dim str_spl$()
  70. Dim lng_val#(0 To 1)
  71. Dim lng_ing&(0 To 1)
  72. Dim str_coll$()
  73. Dim lng_c&
  74. Dim str_res$
  75. Dim lng_Opd&
  76.  
  77.    vExpresion$ = Replace$(vExpresion$, " ", "")
  78.    vExpresion$ = Replace$(vExpresion$, ",", ".")
  79.  
  80.    If (Len(vExpresion$)) Then
  81.        Do
  82.  
  83.            lng_Opd& = BuscarOperando(vExpresion$)
  84.            If (lng_Opd& > -1) Then
  85.                str_spl$ = Split(vExpresion$, Operandos(lng_Opd&), 2)
  86.  
  87.                If (lng_Opd& = eOperandos.eRaiz) Then
  88.                    lng_val#(0) = GetVal(str_spl$(UBound(str_spl$)), &H0, False)
  89.                    str_res$ = Sqr(lng_val#(0))
  90.                    vExpresion$ = Replace$(vExpresion$, Operandos(lng_Opd&) & lng_val#(0), str_res$)
  91.  
  92.                ElseIf (lng_Opd& <= eOperandos.eResta) Then
  93.  
  94.                    lng_val#(0) = GetVal(str_spl$(0), &H0, True)
  95.                    lng_val#(1) = GetVal(str_spl$(1), &H0, False)
  96.  
  97.                    lng_ing&(0) = InStr(1, str_spl$(0), Incognita, vbTextCompare)
  98.                    lng_ing&(1) = InStr(1, str_spl$(1), Incognita, vbTextCompare)
  99.  
  100.  
  101.                    Select Case lng_Opd&
  102.                        Case eOperandos.ePotencia
  103.                            str_res$ = lng_val#(0) ^ lng_val#(1)
  104.  
  105.                        Case eOperandos.eMultiplicacion
  106.                            str_res$ = lng_val#(0) * lng_val#(1)
  107.  
  108.                        Case eOperandos.eDivicion
  109.                            str_res$ = FormatNumber(lng_val#(0) / lng_val#(1), 9)
  110.  
  111.                        Case eOperandos.eSuma
  112.                            str_res$ = lng_val#(0) + lng_val#(1)
  113.  
  114.                        Case eOperandos.eResta
  115.                            str_res$ = lng_val#(0) - lng_val#(1)
  116.  
  117.                    End Select
  118.                    vExpresion$ = Replace$(vExpresion$, lng_val#(0) & Operandos(lng_Opd&) & lng_val#(1), str_res$)
  119.  
  120.                Else
  121.                    ReduccionDeOperandos = vExpresion$
  122.                    Exit Function
  123.  
  124.                End If
  125.  
  126.            End If
  127.  
  128.        Loop Until lng_Opd& = -1
  129.  
  130.    End If
  131.  
  132.    ReduccionDeOperandos = vExpresion$
  133.  
  134. End Function
  135.  
  136. Public Function BuscarOperando(ByVal vExpresion$, Optional ByVal Reverse As Boolean = False, Optional ByRef Inpos&) As Long
  137. Dim lng_Opd&
  138.    lng_Opd& = -1
  139.    If (Len(vExpresion$)) Then
  140.        For lng_Opd& = 2 To UBound(Operandos)
  141.            If (Reverse) Then
  142.                Inpos& = InStrRev(vExpresion$, Operandos(lng_Opd&), Len(vExpresion$))
  143.            Else
  144.                Inpos& = InStr(1, vExpresion$, Operandos(lng_Opd&))
  145.            End If
  146.            If (Inpos&) Then
  147.                Exit For
  148.            End If
  149.        Next lng_Opd&
  150.        If (lng_Opd& = UBound(Operandos) + 1) Then
  151.            BuscarOperando = -1
  152.        Else
  153.            BuscarOperando = lng_Opd&
  154.        End If
  155.    End If
  156. End Function
  157.  
  158. Public Function GetVal(ByVal vExpresion$, ByRef OutPos As Long, Optional ByVal Reverse As Boolean = False) As Double
  159. Dim str_res$
  160.    If (Len(vExpresion$)) Then
  161.        str_res$ = BuscarOperando(vExpresion$, Reverse, OutPos)
  162.        If (Reverse) Then
  163.            If (str_res$ = -1) Then
  164.                OutPos = 1
  165.            End If
  166.            GetVal = Val(Mid$(vExpresion$, OutPos))
  167.        Else
  168.            If (str_res$ = -1) Then
  169.                GetVal = Val(Mid$(vExpresion$, 1))
  170.                OutPos = Len(vExpresion$)
  171.            Else
  172.                GetVal = Val(Mid$(vExpresion$, 1, OutPos))
  173.            End If
  174.        End If
  175.    End If
  176. End Function
  177.  
  178. Private Sub Class_Initialize()
  179.    Operandos(eOperandos.eParentesisI) = "("
  180.    Operandos(eOperandos.eParentesisF) = ")"
  181.    Operandos(eOperandos.ePotencia) = "^"
  182.    Operandos(eOperandos.eRaiz) = "sqrt"
  183.    Operandos(eOperandos.eMultiplicacion) = "*"
  184.    Operandos(eOperandos.eDivicion) = "/"
  185.    Operandos(eOperandos.eSuma) = "+"
  186.    Operandos(eOperandos.eResta) = "-"
  187. End Sub
  188.  
  189.  

Ej.

Código
  1.  
  2. Private Sub Form_Load()
  3. Dim cls_ecuLineal As New cls_ecuLineal
  4.    With cls_ecuLineal
  5.        Dim str$, str2$
  6.        str2$ = "((7 + 4 * 5 + 4)) + 54 + (42) * (4 * (8 / (45 * 10)))*sqrt(9)"
  7.        Do
  8.            DoEvents
  9.            str$ = .GetParentesis(str2$)
  10.            If Len(str2$) <> Len(str$) Then
  11.                str2$ = Replace(str2, "(" & str$ & ")", .ReduccionDeOperandos(str$))
  12.            Else
  13.                MsgBox .ReduccionDeOperandos(str$) & vbNewLine & ((7 + 4 * 5 + 4)) + 54 + (42) * (4 * (8 / (45 * 10))) * Sqr(9)
  14.                Exit Do
  15.            End If
  16.        Loop
  17.    End With
  18. End Sub
  19.  
  20.  

P.D.: Haber si mañana lo termino.

Dulces Lunas!¡.


En línea

The Dark Shadow is my passion.
Edu


Desconectado Desconectado

Mensajes: 1.082


Ex XXX-ZERO-XXX


Ver Perfil
Re: Sacar numeros de una ecuacion? reto?
« Respuesta #11 en: 12 Marzo 2011, 20:38 pm »

Ma black, sos un kapo!, siguelo para tener otro codigo mas creado por vs, porq para mi no ya q no entiendo ni la mitad de las cosas q haces xD
Gracias! yo pense q se podia hacer mas simple pero se ve q esta dificil, de ultima terminen este tema como un reto ;)


En línea

79137913


Desconectado Desconectado

Mensajes: 1.169


4 Esquinas


Ver Perfil WWW
Re: Sacar numeros de una ecuacion? reto?
« Respuesta #12 en: 14 Marzo 2011, 16:58 pm »

HOLA!!!

Mirate este codigo, te va a servir para el programa...

http://foro.elhacker.net/programacion_visual_basic/source_multisplit7913_un_split_diferente_xd-t321862.0.html

GRACIAS POR LEER!!!
En línea

"Como no se puede igualar a Dios, ya he decidido que hacer, ¡SUPERARLO!"
"La peor de las ignorancias es no saber corregirlas"

 79137913                          *Shadow Scouts Team*
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Reto: Números primos en python
Ejercicios
Novlucker 6 10,173 Último mensaje 24 Noviembre 2010, 16:02 pm
por Novlucker
Sacar numeros de una ecuacion? como?
.NET (C#, VB.NET, ASP)
Edu 8 5,722 Último mensaje 14 Marzo 2011, 04:07 am
por .mokk.
[Reto] Ordenar Ecuacion!
Programación Visual Basic
Edu 4 2,440 Último mensaje 3 Abril 2011, 23:02 pm
por Edu
[RETO] + Funcion Extraer Numeros de Cadenas! [Cpp/C] « 1 2 3 4 »
Programación C/C++
x64core 39 34,456 Último mensaje 8 Enero 2012, 00:58 am
por Eternal Idol
[RETO] + Funcion Extraer Numeros de Cadenas! « 1 2 ... 5 6 »
Programación Visual Basic
x64core 55 27,298 Último mensaje 9 Enero 2012, 10:26 am
por Psyke1
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines