Código:
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick 'Utilizamos una variable estática que almacenará 'su valor cada vez que entremos en este evento Dim lineas, lineas_desocupadas, lineas_ocupadas As Integer Dim valor As Double 'velocidad = 0 valor = 0 lineas = Txt_num_lineas.Text lineas_ocupadas = List_llamando.Items.Count Txt_lineas_desocupadas.Text = lineas - lineas_ocupadas Txt_ext_espera.Text = List_ext.Items.Count Timer_duracion.Enabled = True Timer_entrante.Enabled = True If Radio_lenta.Checked = True Then velocidad = 120 valor = 0.83 Else If Radio_rapida.Checked = True Then velocidad = 80 valor = 1.25 End If End If Static bteContador As Byte If bteContador = velocidad Then 'Paramos el control Timer Timer.Stop() Timer_entrante.Stop() Timer_duracion.Stop() 'Lo deshabilitamos para asegurarnos su parada Timer.Enabled = False Timer_entrante.Enabled = False Timer_duracion.Enabled = False MsgBox("Simulación terminada", MsgBoxStyle.Information, "Proyecto I") Progress_simulacion.Value = 0 Else 'Incrementamos en una unidad la variable estática bteContador = bteContador + 1 Progress_simulacion.Value = bteContador * valor End If End Sub Private Sub Btn_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Start.Click If (Txt_num_lineas.Text = "") Or (Txt_num_lineas.Text <= 0) Then MsgBox("Debe introducir un número mayor a 0 (cero) en el campo Número de Líneas", MsgBoxStyle.Critical, "Proyecto I") End If If (Radio_lenta.Checked = False) And (Radio_rapida.Checked = False) Then MsgBox("Debe seleccionar una velocidad de simulación", MsgBoxStyle.Critical, "Proyecto I") End If Btn_Start.Enabled = False Timer.Enabled = True End Sub Private Sub Timer_duracion_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_duracion.Tick Static bteContador_duracion As Byte Dim ticker_duracion, bandera As Double Dim banderas As String If Radio_lenta.Checked = True Then velocidad = 80 Else If Radio_rapida.Checked = True Then velocidad = 60 End If End If If bteContador_duracion = velocidad Then 'Paramos el control Timer 'Timer_duracion.Stop() 'Lo deshabilitamos para asegurarnos su parada 'Timer_duracion.Enabled = False Else 'Incrementamos en una unidad la variable estática ticker_duracion = bteContador_duracion * 4 bandera = List_duracion_llamada.Items(0).Text If (List_duracion_llamada.Items(0).Text <= ticker_duracion) Then banderas = List_llamando.Items(0).Text List_llamando.Items.RemoveAt(0) List_duracion_llamada.Items.RemoveAt(0) Txt_lineas_ocupadas.Text = List_llamando.Items.Count() Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count() Txt_llamadas_done.Text = Txt_llamadas_done.Text + 1 End If bteContador_duracion = bteContador_duracion + 1 End If End Sub Private Sub Timer_entrante_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_entrante.Tick Static bteContador_entrante As Byte Dim ticker_entrante As Integer If Radio_lenta.Checked = True Then velocidad = 80 Else If Radio_rapida.Checked = True Then velocidad = 60 End If End If If bteContador_entrante = velocidad Then 'Paramos el control Timer 'Timer_entrante.Stop() 'Lo deshabilitamos para asegurarnos su parada 'Timer_entrante.Enabled = False Else 'Incrementamos en una unidad la variable estática 'ticker = bteContador_entrante ticker_entrante = bteContador_entrante * 4 'List_minuto_llegada.Items(0).Selected = True If (List_minuto_llegada.Items(0).Text <= ticker_entrante) Then 'List_ext.Items(0).Selected = True If List_espera.Items.Count > 0 Then List_llamando.Items.Add(List_espera.Items(0).Text) List_espera.Items.RemoveAt(0) Txt_ext_espera.Text = List_espera.Items.Count() Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count() Txt_lineas_ocupadas.Text = List_llamando.Items.Count() End If If List_llamando.Items.Count < Txt_num_lineas.Text Then List_llamando.Items.Add(List_ext.Items(0).Text) List_minuto_llegada.Items.RemoveAt(0) List_ext.Items.RemoveAt(0) Txt_lineas_desocupadas.Text = Txt_num_lineas.Text - List_llamando.Items.Count() Txt_lineas_ocupadas.Text = List_llamando.Items.Count() Else List_espera.Items.Add(List_ext.Items(0).Text) List_ext.Items.RemoveAt(0) List_minuto_llegada.Items.RemoveAt(0) Txt_ext_espera.Text = List_espera.Items.Count() End If End If bteContador_entrante = bteContador_entrante + 1 End If End Sub End Class