Foros del Web » Programación para mayores de 30 ;) » .NET »

Visual Basic 2010, busco forma de separar términos

Estas en el tema de Visual Basic 2010, busco forma de separar términos en el foro de .NET en Foros del Web. Hola chicos, ando buscando una forma, en la que pueda separar dos términos es decir y que pueda guardar su operador, de tal forma que: ...
  #1 (permalink)  
Antiguo 06/10/2010, 21:00
Avatar de thegodinez  
Fecha de Ingreso: octubre-2010
Ubicación: Culiacán, Sinaloa
Mensajes: 54
Antigüedad: 13 años, 7 meses
Puntos: 5
Pregunta Visual Basic 2010, busco forma de separar términos



Hola chicos, ando buscando una forma, en la que pueda separar dos términos es decir y que pueda guardar su operador, de tal forma que:
10+20=30
Variable 1= 10
Operador1="+"
Variable 2= 20
Igualdad="="
Variable 3=30

Toda respuesta construtiva será bienvenida.
  #2 (permalink)  
Antiguo 07/10/2010, 00:16
 
Fecha de Ingreso: septiembre-2009
Ubicación: Medellin
Mensajes: 21
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Visual Basic 2010, busco forma de separar términos

No se mucho de Basic asi que seguramente hay formas mas faciles de hacerlo, pero que te mando el codigo, espero que te sirva.

Código vb:
Ver original
  1. Public Sub separar(ByVal exp As String)
  2.         Dim varible1 = ""
  3.         Dim operador = ""
  4.         Dim varible2 = ""
  5.         Dim igual = ""
  6.         Dim resultado = ""
  7.         Dim encontro As Boolean = False
  8.  
  9.         Dim i = 0
  10.  
  11.         While exp.Substring(i, 1) <> "="
  12.  
  13.             If encontro = False Then
  14.                 varible1 = varible1 + exp.Substring(i, 1)
  15.             End If
  16.             If exp.Substring(i, 1) = "+" Or exp.Substring(i, 1) = "-" Or exp.Substring(i, 1) = "/" Or exp.Substring(i, 1) = "*" Then
  17.                 operador = exp.Substring(i, 1)
  18.                 encontro = True
  19.             End If
  20.  
  21.             If encontro = True Then
  22.                 varible2 = varible2 + exp.Substring(i, 1)
  23.             End If
  24.  
  25.             i = i + 1
  26.         End While
  27.  
  28.         igual = "="
  29.         varible1 = varible1.Substring(0, varible1.Length - 1)
  30.         varible2 = varible2.Substring(1, varible2.Length - 1)
  31.         resultado = exp.Substring(varible1.Length + varible2.Length + 2, exp.Length - varible1.Length - varible2.Length - 2)
  32.  
  33.  
  34.         TextBox2.Text = varible1
  35.         TextBox3.Text = operador
  36.         TextBox4.Text = varible2
  37.         TextBox5.Text = igual
  38.         TextBox6.Text = resultado
  39.  
  40.     End Sub
  #3 (permalink)  
Antiguo 07/10/2010, 20:17
Avatar de thegodinez  
Fecha de Ingreso: octubre-2010
Ubicación: Culiacán, Sinaloa
Mensajes: 54
Antigüedad: 13 años, 7 meses
Puntos: 5
Respuesta: Visual Basic 2010, busco forma de separar términos

Cita:
Iniciado por sergio701 Ver Mensaje
No se mucho de Basic asi que seguramente hay formas mas faciles de hacerlo, pero que te mando el codigo, espero que te sirva.

Código vb:
Ver original
  1. Public Sub separar(ByVal exp As String)
  2.         Dim varible1 = ""
  3.         Dim operador = ""
  4.         Dim varible2 = ""
  5.         Dim igual = ""
  6.         Dim resultado = ""
  7.         Dim encontro As Boolean = False
  8.  
  9.         Dim i = 0
  10.  
  11.         While exp.Substring(i, 1) <> "="
  12.  
  13.             If encontro = False Then
  14.                 varible1 = varible1 + exp.Substring(i, 1)
  15.             End If
  16.             If exp.Substring(i, 1) = "+" Or exp.Substring(i, 1) = "-" Or exp.Substring(i, 1) = "/" Or exp.Substring(i, 1) = "*" Then
  17.                 operador = exp.Substring(i, 1)
  18.                 encontro = True
  19.             End If
  20.  
  21.             If encontro = True Then
  22.                 varible2 = varible2 + exp.Substring(i, 1)
  23.             End If
  24.  
  25.             i = i + 1
  26.         End While
  27.  
  28.         igual = "="
  29.         varible1 = varible1.Substring(0, varible1.Length - 1)
  30.         varible2 = varible2.Substring(1, varible2.Length - 1)
  31.         resultado = exp.Substring(varible1.Length + varible2.Length + 2, exp.Length - varible1.Length - varible2.Length - 2)
  32.  
  33.  
  34.         TextBox2.Text = varible1
  35.         TextBox3.Text = operador
  36.         TextBox4.Text = varible2
  37.         TextBox5.Text = igual
  38.         TextBox6.Text = resultado
  39.  
  40.     End Sub
He entendido alguna parte del código, ahora me lo podrias explicar en caso de que fueran tres variables?.
  #4 (permalink)  
Antiguo 07/10/2010, 20:33
 
Fecha de Ingreso: septiembre-2009
Ubicación: Medellin
Mensajes: 21
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Visual Basic 2010, busco forma de separar términos

La idea es encontrar solo hasta 3 variables o n variables?
  #5 (permalink)  
Antiguo 07/10/2010, 20:49
Avatar de thegodinez  
Fecha de Ingreso: octubre-2010
Ubicación: Culiacán, Sinaloa
Mensajes: 54
Antigüedad: 13 años, 7 meses
Puntos: 5
Respuesta: Visual Basic 2010, busco forma de separar términos

Cita:
Iniciado por sergio701 Ver Mensaje
La idea es encontrar solo hasta 3 variables o n variables?
N variables, aunque tu ayuda ha sido muy buena amigo :D , si lo puedes hacer para n variables te lo agradeceria mucho.
  #6 (permalink)  
Antiguo 07/10/2010, 22:01
 
Fecha de Ingreso: septiembre-2009
Ubicación: Medellin
Mensajes: 21
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Visual Basic 2010, busco forma de separar términos

pongo el siguiente codigo que los que hace es separar la exprecion en un arreglo.
luego pongo cada escprecion en una linea del texbox7.

Código:
    Public Sub separarn(ByVal exp As String)
        Dim separados(100) As String
        Dim encontro As Boolean = False

        Dim c = 0

        For i = 0 To exp.Length - 1

            If exp.Substring(i, 1) <> "+" And exp.Substring(i, 1) <> "-" And exp.Substring(i, 1) <> "/" And exp.Substring(i, 1) <> "*" And exp.Substring(i, 1) <> "=" Then
                separados(c) = separados(c) + exp.Substring(i, 1)
            End If

            If exp.Substring(i, 1) = "+" Or exp.Substring(i, 1) = "-" Or exp.Substring(i, 1) = "/" Or exp.Substring(i, 1) = "*" Or exp.Substring(i, 1) = "=" Then
                c = c + 1
                separados(c) = exp.Substring(i, 1)
                c = c + 1
            End If

        Next

        TextBox7.Text = ""
        For Each var As String In separados
            If var <> "" Then
                TextBox7.Text = TextBox7.Text + var + vbCrLf
            End If
        Next

    End Sub

Etiquetas: basic, visual, formulario
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:05.