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

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  [SRC/VB.Net]Ec2Solver
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [SRC/VB.Net]Ec2Solver  (Leído 1,469 veces)
[L]ord [R]NA


Desconectado Desconectado

Mensajes: 1.513

El Dictador y Verdugo de H-Sec


Ver Perfil WWW
[SRC/VB.Net]Ec2Solver
« en: 18 Marzo 2011, 03:53 am »

Soluciona Ecuaciones de 2do Grado... contiene un modulo el cual cree especialmente para esta ocasion.

Modulo Ec2Solver
Código
  1. Module Ec2Solver
  2.    '*----------------------------------------------------------------------------------------------*
  3.    '| Author: [L]ord [R]NA                                                                         |
  4.    '| Country: Dominican Republic                                                                  |
  5.    '*----------------------------------------------------------------------------------------------*
  6.    ' Description: A Module to solve 2nd Degree Equations. The Module Ec2Solver has a Function that |
  7.    ' Get the First 3 constant value of the equation And 2 Double Variables are public in the module|
  8.    ' to get the possible values of X. If everything is Ok the Function return True and if it's     |
  9.    ' something wrong Return False.                                                                 |
  10.    '*----------------------------------------------------------------------------------------------*
  11.    '|Website: http://lordrna.co.cc/ http://foro.h-sec.org/                                         |
  12.    '|Mail: lordrna@h-sec.org                                                                       |
  13.    '*----------------------------------------------------------------------------------------------*
  14.    Public X1 As Double, X2 As Double
  15.    Dim A1 As Double, B1 As Double, C1 As Double
  16.  
  17.    Public Function Ec2Solver(ByVal A As String, ByVal B As String, ByVal C As String) As Boolean
  18.        If Double.TryParse(A, A1) And Double.TryParse(B, B1) And Double.TryParse(C, C1) Then
  19.            Ec2Solver = Ec2Solver(A1, B1, C1)
  20.        Else
  21.            Ec2Solver = False
  22.        End If
  23.    End Function
  24.  
  25.    Public Function Ec2Solver(ByVal A As Double, ByVal B As Double, ByVal C As Double) As Boolean
  26.  
  27.        Dim temp As Double
  28.        X1 = 0
  29.        X2 = 0
  30.        If A = 0 Then Ec2Solver = False
  31.        If B = 0 And A <> 0 Then
  32.            If C / A > 0 Then
  33.                Ec2Solver = False
  34.            Else
  35.                If C = 0 Then
  36.                    Ec2Solver = True
  37.                Else
  38.                    X1 = -System.Math.Sqrt(System.Math.Abs(C / A))
  39.                    X2 = System.Math.Sqrt(System.Math.Abs(C / A))
  40.                    Ec2Solver = True
  41.                End If
  42.            End If
  43.        ElseIf C = 0 Then
  44.            X1 = B / A
  45.            Ec2Solver = True
  46.        Else
  47.            temp = (System.Math.Pow(B, 2)) - 4 * A * C
  48.            If temp < 0 Then
  49.                Ec2Solver = False
  50.            Else
  51.                temp = System.Math.Sqrt(temp) / (2 * A)
  52.                X1 = -B + temp
  53.                X2 = -B - temp
  54.                Ec2Solver = True
  55.            End If
  56.        End If
  57.  
  58.    End Function
  59. End Module
  60.  

Source
Código
  1. Public Class Form1
  2.  
  3.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.        A.Clear()
  5.        B.Clear()
  6.        C.Clear()
  7.        X1.Clear()
  8.        X2.Clear()
  9.    End Sub
  10.  
  11.    Private Sub A_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A.Click
  12.        A.Text = ""
  13.    End Sub
  14.  
  15.    Private Sub B_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B.Click
  16.        B.Text = ""
  17.    End Sub
  18.  
  19.    Private Sub C_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C.Click
  20.        C.Text = ""
  21.    End Sub
  22.  
  23.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  24.        If Len(A.Text) = 0 Or A.Text = "0" Then A.Text = "1"
  25.        If Len(B.Text) = 0 Then B.Text = "0"
  26.        If Len(C.Text) = 0 Then C.Text = "0"
  27.  
  28.        If Ec2Solver.Ec2Solver(A.Text, B.Text, C.Text) = True Then
  29.            X1.Text = Str(Ec2Solver.X1)
  30.            X2.Text = Str(Ec2Solver.X2)
  31.        Else
  32.            X1.Text = "Sin Solucion"
  33.            X2.Text = "Real"
  34.        End If
  35.    End Sub
  36. End Class


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines