VERSION 5.00 Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" Begin VB.Form frmCarro Caption = "Carro" ClientHeight = 4770 ClientLeft = 60 ClientTop = 345 ClientWidth = 6330 LinkTopic = "Form1" ScaleHeight = 4770 ScaleWidth = 6330 StartUpPosition = 3 'Windows Default Begin VB.Timer Relogio Left = 5760 Top = 3840 End Begin VB.Frame fraAutonomia Caption = "Autonomia : " Height = 1455 Left = 3480 TabIndex = 10 Top = 600 Width = 2655 Begin VB.TextBox txtAutonomiaTempo Height = 315 Left = 1080 TabIndex = 14 Top = 960 Width = 1095 End Begin VB.TextBox txtAutonomiaKlms Height = 315 Left = 1080 TabIndex = 12 Top = 480 Width = 1095 End Begin VB.Label lblAutonomiaTempo Alignment = 1 'Right Justify Caption = "Tempo :" Height = 255 Left = 240 TabIndex = 13 Top = 960 Width = 615 End Begin VB.Label lblAutonomiaKlms Alignment = 1 'Right Justify Caption = "Klms :" Height = 255 Left = 240 TabIndex = 11 Top = 480 Width = 615 End End Begin VB.TextBox txtKlm Height = 375 Left = 1800 TabIndex = 9 Top = 1800 Width = 1215 End Begin VB.CommandButton cmdEncherDeposito Caption = "Encher Depósito" Height = 495 Left = 3240 TabIndex = 7 Top = 3840 Width = 1455 End Begin VB.CommandButton cmdParar Caption = "Parar" Height = 495 Left = 1560 TabIndex = 6 Top = 3840 Width = 1095 End Begin VB.TextBox txtConsumo Height = 375 Left = 1800 TabIndex = 4 Top = 1200 Width = 1215 End Begin VB.TextBox txtDeposito Height = 375 Left = 1800 TabIndex = 2 Top = 600 Width = 1215 End Begin MSComctlLib.Slider sldVelocidade Height = 630 Left = 1320 TabIndex = 0 Top = 2640 Width = 3975 _ExtentX = 7011 _ExtentY = 1111 _Version = 393216 Max = 150 TickStyle = 1 TickFrequency = 10 End Begin VB.Label lblKlm Alignment = 1 'Right Justify Caption = "Klm :" Height = 255 Left = 480 TabIndex = 8 Top = 1800 Width = 1095 End Begin VB.Label lblVelocidade Caption = "Velocidade : ( Km/h )" Height = 495 Left = 240 TabIndex = 5 Top = 2640 Width = 975 End Begin VB.Label lblConsumo Alignment = 1 'Right Justify Caption = "Consumo :" Height = 255 Left = 480 TabIndex = 3 Top = 1200 Width = 1095 End Begin VB.Label lblDeposito Alignment = 1 'Right Justify Caption = "Combustivel :" Height = 255 Left = 480 TabIndex = 1 Top = 600 Width = 1095 End End Attribute VB_Name = "frmCarro" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private WithEvents Carro As cCarro Attribute Carro.VB_VarHelpID = -1 Private Sub cmdEncherDeposito_Click() Carro.EncherDeposito cmdEncherDeposito.Enabled = False End Sub Private Sub cmdParar_Click() sldVelocidade.Value = 0 End Sub Private Sub Form_Load() Set Carro = New cCarro sldVelocidade.Max = Carro.VelocidadeMaxima Carro.EncherDeposito txtConsumo.Text = CStr(Carro.Consumo) txtDeposito.Text = Format(Carro.Deposito.Quantidade, "Standard") cmdParar.Enabled = False cmdEncherDeposito.Enabled = False Carro.InitRelogio Relogio End Sub Private Sub sldVelocidade_Change() Carro.Velocidade = sldVelocidade.Value cmdParar.Enabled = Carro.Velocidade > 0 cmdEncherDeposito.Enabled = Carro.Velocidade = 0 CalculaAutonomia End Sub ' Resposta ao evento AlteracaoConsumo disparado pelo objecto Carro Private Sub Carro_AlteracaoConsumo() txtConsumo.Text = CStr(Carro.Consumo) End Sub Private Sub CalculaAutonomia() Dim AutonomiaKlms As Double Dim AutonomiaTempo As Double If Carro.Velocidade > 0 Then AutonomiaKlms = (Carro.Deposito.Quantidade / Carro.Consumo) * 100 AutonomiaTempo = AutonomiaKlms / Carro.Velocidade txtAutonomiaKlms.Text = Format(AutonomiaKlms, "Standard") txtAutonomiaTempo.Text = Format(AutonomiaTempo, "Standard") Else txtAutonomiaKlms.Text = "" txtAutonomiaTempo.Text = "" End If End Sub