martes, 18 de octubre de 2016

Multiplicador constante en visual basic - Numeros aleatorios

Muy buen día Amig@s, aquí la continuación de números aleatorios hoy sera el multiplicador constante.

Empezamos creando una ventana similar a esta:
:
Nesceitaremos 5 textbox y 3 botones, donde contendrá el numero de periodos, la constante y por supuesto la semilla, el cuadro de en medio es donde se desglozara la operación.

Ojo text1 es el numero de periodos, el text2 es la constante, semilla es la semilla, text3 es el cuadro de en medio y text4 es el de abajo

En el botón generar ingresamos el siguiente código:
Public Class ventanaMC

    Private Sub Gcm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Gcm.Click
Creamos 6 variables, 2 de tipo integer y 4 de tipo double
        Dim n_periodo As Integer
        Dim tamaño As Integer
        Dim multiplicador As Double
        Dim nuevo_multi As Double
        Dim constante As Double
        Dim divisor As Double

        n_periodo = text1.Text
        For i = 1 To n_periodo
            constante = text2.Text
            multiplicador = constante * semilla.Text

            text4.Text = multiplicador



            tamaño = Len(text4.Text)
            If tamaño = 7 Then
                text4.Text = "0" & multiplicador
            End If

            If tamaño = 6 Then
                text4.Text = "00" & multiplicador
            End If

            If tamaño = 5 Then
                text4.Text = "000" & multiplicador
            End If

            If tamaño = 4 Then
                text4.Text = "0000" & multiplicador
            End If

            If tamaño = 3 Then
                text4.Text = "00000" & multiplicador
            End If
            nuevo_multi = Mid(text4.Text, 3, 4)
            semilla.Text = nuevo_multi
            divisor = nuevo_multi / 10000


            text3.Text = text3.Text & vbCrLf & "Periodo  [" & i & "]  " & text4.Text & "    N°centro: " & nuevo_multi & "    = " & divisor

            If i = n_periodo Then
                Label1.Text = "Resultado:"
            End If

        Next i
    End Sub
Boton para limpiar 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        text1.Clear()
        text2.Clear()
        text3.Clear()
        text4.Clear()
        semilla.Clear()

    End Sub
Boton para salir
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form1.Show()
        Me.Hide()

    End Sub
End Class
 Descarga el proyecto aquí:
 http://kudoflow.com/2JDg


No hay comentarios:

Publicar un comentario

Entrada destacada

Como hacer una calculadora en visual basic

Hola amig@s para los que estén usando el lenguje de programacion de visual basic en su versión 2010 0 2012 aquí les traigo este ejemplo de c...