Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/10/2010, 15:06
abuitrago81
 
Fecha de Ingreso: mayo-2010
Mensajes: 41
Antigüedad: 14 años, 10 meses
Puntos: 0
Respuesta: Paso de variables de un formulario a otro.

PONGO TODO EL CÓDIGO QUE TENGO POR SI AYUDA:

FORM 2
Código vb:
Ver original
  1. Public Class Form2
  2.  
  3.  
  4.     'DECLARACIÓN DE VARIABLES.
  5.    Dim tarifa_coche As Decimal = 0.5
  6.     Dim tarifa_camion As Decimal = 0.5
  7.     Dim tarifa_moto As Decimal = 2.5
  8.     Dim tarifa_bus As Decimal = 0.75
  9.     Dim descuento As Decimal = 0.5
  10.     Dim aux_descuento As Decimal = 0
  11.     Dim tara As Decimal = 0.25
  12.     Public toneladas As Decimal
  13.     Dim aux As Decimal
  14.     Public km As Decimal
  15.     Public total As Decimal
  16.     Dim tipo As Integer
  17.  
  18.     'EVENTOS BOTONES TIPO DE VEHÍCULO
  19.    Private Sub boton_coche_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_coche.Click
  20.         Me.boton_coche.Image = PEAJE.My.Resources.Resources.ICO_COCHE_ON
  21.         Me.boton_camion.Image = PEAJE.My.Resources.Resources.ICO_CAMION
  22.         Me.boton_moto.Image = PEAJE.My.Resources.Resources.ICO_MOTO
  23.         Me.boton_bus.Image = PEAJE.My.Resources.Resources.ICO_BUS
  24.         Me.caja_tara.Enabled = "False"
  25.         Me.boton_descuento.Enabled = "True"
  26.         aux = tarifa_coche
  27.         tipo = 1
  28.     End Sub
  29.  
  30.     Private Sub boton_camion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_camion.Click
  31.         Me.boton_camion.Image = PEAJE.My.Resources.Resources.ICO_CAMION_ON
  32.         Me.boton_coche.Image = PEAJE.My.Resources.Resources.ICO_COCHE
  33.         Me.boton_moto.Image = PEAJE.My.Resources.Resources.ICO_MOTO
  34.         Me.boton_bus.Image = PEAJE.My.Resources.Resources.ICO_BUS
  35.         Me.caja_tara.Enabled = "True"
  36.         Me.boton_descuento.Enabled = "False"
  37.         aux = tarifa_camion
  38.         tipo = 2
  39.     End Sub
  40.  
  41.     Private Sub boton_moto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_moto.Click
  42.         Me.boton_moto.Image = PEAJE.My.Resources.Resources.ICO_MOTO_ON
  43.         Me.boton_camion.Image = PEAJE.My.Resources.Resources.ICO_CAMION
  44.         Me.boton_coche.Image = PEAJE.My.Resources.Resources.ICO_COCHE
  45.         Me.boton_bus.Image = PEAJE.My.Resources.Resources.ICO_BUS
  46.         Me.caja_tara.Enabled = "False"
  47.         Me.boton_descuento.Enabled = "False"
  48.         km = 1
  49.         aux = tarifa_moto
  50.         tipo = 3
  51.     End Sub
  52.  
  53.     Private Sub boton_bus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_bus.Click
  54.         Me.boton_bus.Image = PEAJE.My.Resources.Resources.ICO_BUS_ON
  55.         Me.boton_camion.Image = PEAJE.My.Resources.Resources.ICO_CAMION
  56.         Me.boton_moto.Image = PEAJE.My.Resources.Resources.ICO_MOTO
  57.         Me.boton_coche.Image = PEAJE.My.Resources.Resources.ICO_COCHE
  58.         Me.caja_tara.Enabled = "False"
  59.         Me.boton_descuento.Enabled = "False"
  60.         aux = tarifa_bus
  61.         tipo = 4
  62.     End Sub
  63.  
  64.     'EVENTO DEL BOTÓN DESCUENTO
  65.    Private Sub boton_descuento_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_descuento.Click
  66.         Me.boton_descuento.Image = PEAJE.My.Resources.Resources.DESCUENTO_ON
  67.         If tipo = 1 Then
  68.             aux_descuento = descuento
  69.         End If
  70.     End Sub
  71.  
  72.     'CAJAS DE TEXTO (DATOS)
  73.    Private Sub caja_km_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caja_km.TextChanged
  74.         km = Val(Me.caja_km.Text)
  75.         Form3.caja_km_total.Text = Me.caja_km.Text
  76.     End Sub
  77.  
  78.     Private Sub caja_tara_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caja_tara.TextChanged
  79.         toneladas = Val(Me.caja_tara.Text)
  80.         Form3.caja_tara_total.Text = Me.caja_tara.Text
  81.     End Sub
  82.  
  83.     'EVENTO DEL BOTÓN CALCULAR IMPORTE
  84.    Public Sub boton_calcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_calcular.Click
  85.         Select Case tipo
  86.             Case 1
  87.                 total = (aux * km) - aux_descuento
  88.                 Me.importe_euros.Text = Format(total, "0.00")
  89.                 Me.importe_pesetas.Text = Format(total * 166.386, "0.00")
  90.                 Form3.importe_euros_total.Text = Format(total, "0.00")
  91.                 Form3.importe_pesetas_total.Text = Format(total * 166.386, "0.00")
  92.                 Form3.tipo_vehiculo.Image = PEAJE.My.Resources.Resources.ICO_COCHE_MINI
  93.             Case 2
  94.                 total = (aux * km) + (toneladas * tara)
  95.                 Me.importe_euros.Text = Format(total, "0.00")
  96.                 Me.importe_pesetas.Text = Format(total * 166.386, "0.00")
  97.                 Form3.importe_euros_total.Text = Format(total, "0.00")
  98.                 Form3.importe_pesetas_total.Text = Format(total * 166.386, "0.00")
  99.                 Form3.tipo_vehiculo.Image = PEAJE.My.Resources.Resources.ICO_CAMION_MINI
  100.             Case 3
  101.                 total = aux * km
  102.                 Me.importe_euros.Text = Format(total, "0.00")
  103.                 Me.importe_pesetas.Text = Format(total * 166.386, "0.00")
  104.                 Form3.importe_euros_total.Text = Format(total, "0.00")
  105.                 Form3.importe_pesetas_total.Text = Format(total * 166.386, "0.00")
  106.                 Form3.tipo_vehiculo.Image = PEAJE.My.Resources.Resources.ICO_MOTO_MINI
  107.             Case 4
  108.                 total = aux * km
  109.                 Me.importe_euros.Text = Format(total, "0.00")
  110.                 Me.importe_pesetas.Text = Format(total * 166.386, "0.00")
  111.                 Form3.importe_euros_total.Text = Format(total, "0.00")
  112.                 Form3.importe_pesetas_total.Text = Format(total * 166.386, "0.00")
  113.                 Form3.tipo_vehiculo.Image = PEAJE.My.Resources.Resources.ICO_BUS_MINI
  114.         End Select
  115.     End Sub
  116.  
  117.     ' EVENTO PARA EL BOTÓN DE TICKET
  118.    Private Sub boton_ticket_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_ticket.Click
  119.         Dim fticket As New Form3
  120.         Form3.Show()
  121.         Me.Close()
  122.     End Sub
  123. End Class

FORM3

Código vb:
Ver original
  1. Public Class Form3
  2.     Public importe As Decimal
  3.     Public pago As Decimal
  4.  
  5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles boton_pago.Click
  6.         Dim fbarrera As New Form4
  7.         Form4.Show()
  8.         Me.Close()
  9.     End Sub
  10.  
  11.     Private Sub caja_pago_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles caja_pago.TextChanged
  12.         pago = Val(Me.caja_pago.Text)
  13.         Form4.etiqueta_pagado.Text = Format(pago, "0.00")
  14.     End Sub
  15. End Class