USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Datas/Números/Strings)

Título da Dica:  Conversão de volume de combustível para 20 graus
Postada em 6/10/2002 por San.dro            
Para quem trabalha com combustível (Gasolina, Diesel, Querosene), ter uma rotina que faça a conversão de uma densidade Y, a determinada temperatura, para 20´C, que é a utilizada para faturamento, é fundamental.'
Além disso, conhecer o Fator de Correção de volume, que converte o volume numa certa temperatura/densidade, para 20´C, também faz parte.

As funções são:
    DensA20 = dens20(TempDaAmostra, DensDaAmostra)
    Fator = fcv(TempDoProduto, DensA20Graus)

Os códigos:

Function Dens20(tp, Dens) As Single
    Dim tb(21, 5) As Double, hyc As Double
    Dim dT As Single, x As Integer, d20 As Double
    On Error GoTo Dens20Erro
    If IsNull(tp) Or IsNull(Dens) Then Dens20 = 0: Exit Function
    If Dens >= 2 Then Dens20 = 0: Exit Function
    
    tb(1, 1) = -4.5946489678832E-03: tb(1, 2) = 0.006123243179568: tb(1, 3) = -3.17074831323E-05: tb(1, 4) = 5.48397230037E-05: tb(1, 5) = 0.498
    tb(2, 1) = -4.4617912555853E-03: tb(2, 2) = 0.004064744943305: tb(2, 3) = -2.63476576878E-05: tb(2, 4) = 4.45167480908E-05: tb(2, 5) = 0.518
    tb(3, 1) = -4.2635157420811E-03: tb(3, 2) = 0.005464985535707: tb(3, 3) = -2.63293867091E-05: tb(3, 4) = 4.38862463121E-05: tb(3, 5) = 0.539
    tb(4, 1) = -3.9313336083154E-03: tb(4, 2) = 4.8491424883736E-03: tb(4, 3) = -1.71988380071E-05: tb(4, 4) = 2.71198135388E-05: tb(4, 5) = 0.559
    tb(5, 1) = -3.5459928199062E-03: tb(5, 2) = 4.1555627486597E-03: tb(5, 3) = -0.000017408240554: tb(5, 4) = 2.72052538293E-05: tb(5, 5) = 0.579
    tb(6, 1) = -4.4795785597695E-03: tb(6, 2) = 5.7678078599348E-03: tb(6, 3) = -3.84017053043E-05: tb(6, 4) = 6.36945533674E-05: tb(6, 5) = 0.6
    tb(7, 1) = -2.4361018961719E-03: tb(7, 2) = 2.3329279647329E-03: tb(7, 3) = -1.5650912583E-06: tb(7, 4) = 1.9239173808E-06: tb(7, 5) = 0.615
    tb(8, 1) = -2.2189302188433E-03: tb(8, 2) = 1.9797818956931E-03: tb(8, 3) = -1.5669676937E-06: tb(8, 4) = 0.00000192696868: tb(8, 5) = 0.635
    tb(9, 1) = -1.9375650211733E-03: tb(9, 2) = 1.5367709455658E-03: tb(9, 3) = -1.5693987823E-06: tb(9, 4) = 1.9307964416E-06: tb(9, 5) = 0.655
    tb(10, 1) = -1.8211308776797E-03: tb(10, 2) = 1.3590733713544E-03: tb(10, 3) = -0.000001570404812: tb(10, 4) = 1.9323318076E-06: tb(10, 5) = 0.675
    tb(11, 1) = -0.001761056212754: tb(11, 2) = 1.2701185634916E-03: tb(11, 3) = -0.000001570923877: tb(11, 4) = 1.9331004067E-06: tb(11, 5) = 0.695
    tb(12, 1) = -1.8105498111601E-03: tb(12, 2) = 1.3412880691687E-03: tb(12, 3) = -1.5704962359E-06: tb(12, 4) = 1.9324854785E-06: tb(12, 5) = 0.746
    tb(13, 1) = -2.2215907273459E-03: tb(13, 2) = 1.8913202829246E-03: tb(13, 3) = -0.000001566944706: tb(13, 4) = 1.9277330177E-06: tb(13, 5) = 0.766
    tb(14, 1) = -0.001950066973645: tb(14, 2) = 1.5367709455658E-03: tb(14, 3) = -1.5692907613E-06: tb(14, 4) = 1.9307964416E-06: tb(14, 5) = 0.786
    tb(15, 1) = -1.7395987201258E-03: tb(15, 2) = 1.2701185634916E-03: tb(15, 3) = -1.5711092769E-06: tb(15, 4) = 1.9331004067E-06: tb(15, 5) = 0.806
    tb(16, 1) = -0.001523256792873: tb(16, 2) = 0.001002829043573: tb(16, 3) = -0.000015729785429: tb(16, 4) = 1.9354098768E-06: tb(16, 5) = 0.826
    tb(17, 1) = -1.3028125169482E-03: tb(17, 2) = 7.349000995177E-04: tb(17, 3) = -1.5748832546E-06: tb(17, 4) = 1.9377248718E-06: tb(17, 5) = 0.846
    tb(18, 1) = -1.1210535017199E-03: tb(18, 2) = 5.200950155166E-04: tb(18, 3) = -1.5764537128E-06: tb(18, 4) = 0.000001939580859: tb(18, 5) = 0.871
    tb(19, 1) = -9.335584519317E-04: tb(19, 2) = 3.048780487805E-04: tb(19, 3) = -1.5780737322E-06: tb(19, 4) = 0.000001941440405: tb(19, 5) = 0.896
    tb(20, 1) = -7.238306025284E-04: tb(20, 2) = 7.12601611711E-05: tb(20, 3) = -1.5798858504E-06: tb(20, 4) = 0.000001943458941: tb(20, 5) = 0.996
    tb(21, 1) = -9.082062326932E-04: tb(21, 2) = 2.563514599689E-04: tb(21, 3) = 7.4474093761E-06: tb(21, 4) = -7.1188764479E-06: tb(21, 5) = 9.999
    
    dT = tp - 20
    hyc = 1 - 0.000023 * dT - 0.00000002 * dT ^ 2
    
    For x = 1 To 21
        d20 = Dens - tb(x, 1) * dT - tb(x, 3) * dT ^ 2
        d20 = d20 / (1 + tb(x, 2) * dT + tb(x, 4) * dT ^ 2)
        d20 = d20 * hyc
        If d20 <= tb(x, 5) Then Exit For
    Next
    If d20 > 0.65 Then
        d20 = Int(d20 * 10000 + 0.5) / 10000
    Else
        d20 = Int(d20 * 1000 + 0.5) / 1000
    End If
    Dens20 = d20
    Exit Function
Dens20Erro:
    Dens20 = 0
End Function

Function Fcv(tp, d20 As Double) As Single
    Dim tb(21, 5) As Double, dT As Double, x As Integer, fator As Double
    On Error GoTo FcvErro
    If IsNull(tp) Or IsNull(d20) Then Fcv = 0: Exit Function
    If d20 >= 2 Then Fcv = 0: Exit Function
    
    tb(1, 1) = -4.5946489678832E-03: tb(1, 2) = 0.006123243179568: tb(1, 3) = -3.17074831323E-05: tb(1, 4) = 5.48397230037E-05: tb(1, 5) = 0.498
    tb(2, 1) = -4.4617912555853E-03: tb(2, 2) = 0.004064744943305: tb(2, 3) = -2.63476576878E-05: tb(2, 4) = 4.45167480908E-05: tb(2, 5) = 0.518
    tb(3, 1) = -4.2635157420811E-03: tb(3, 2) = 0.005464985535707: tb(3, 3) = -2.63293867091E-05: tb(3, 4) = 4.38862463121E-05: tb(3, 5) = 0.539
    tb(4, 1) = -3.9313336083154E-03: tb(4, 2) = 4.8491424883736E-03: tb(4, 3) = -1.71988380071E-05: tb(4, 4) = 2.71198135388E-05: tb(4, 5) = 0.559
    tb(5, 1) = -3.5459928199062E-03: tb(5, 2) = 4.1555627486597E-03: tb(5, 3) = -0.000017408240554: tb(5, 4) = 2.72052538293E-05: tb(5, 5) = 0.579
    tb(6, 1) = -4.4795785597695E-03: tb(6, 2) = 5.7678078599348E-03: tb(6, 3) = -3.84017053043E-05: tb(6, 4) = 6.36945533674E-05: tb(6, 5) = 0.6
    tb(7, 1) = -2.4361018961719E-03: tb(7, 2) = 2.3329279647329E-03: tb(7, 3) = -1.5650912583E-06: tb(7, 4) = 1.9239173808E-06: tb(7, 5) = 0.615
    tb(8, 1) = -2.2189302188433E-03: tb(8, 2) = 1.9797818956931E-03: tb(8, 3) = -1.5669676937E-06: tb(8, 4) = 0.00000192696868: tb(8, 5) = 0.635
    tb(9, 1) = -1.9375650211733E-03: tb(9, 2) = 1.5367709455658E-03: tb(9, 3) = -1.5693987823E-06: tb(9, 4) = 1.9307964416E-06: tb(9, 5) = 0.655
    tb(10, 1) = -1.8211308776797E-03: tb(10, 2) = 1.3590733713544E-03: tb(10, 3) = -0.000001570404812: tb(10, 4) = 1.9323318076E-06: tb(10, 5) = 0.675
    tb(11, 1) = -0.001761056212754: tb(11, 2) = 1.2701185634916E-03: tb(11, 3) = -0.000001570923877: tb(11, 4) = 1.9331004067E-06: tb(11, 5) = 0.695
    tb(12, 1) = -1.8105498111601E-03: tb(12, 2) = 1.3412880691687E-03: tb(12, 3) = -1.5704962359E-06: tb(12, 4) = 1.9324854785E-06: tb(12, 5) = 0.746
    tb(13, 1) = -2.2215907273459E-03: tb(13, 2) = 1.8913202829246E-03: tb(13, 3) = -0.000001566944706: tb(13, 4) = 1.9277330177E-06: tb(13, 5) = 0.766
    tb(14, 1) = -0.001950066973645: tb(14, 2) = 1.5367709455658E-03: tb(14, 3) = -1.5692907613E-06: tb(14, 4) = 1.9307964416E-06: tb(14, 5) = 0.786
    tb(15, 1) = -1.7395987201258E-03: tb(15, 2) = 1.2701185634916E-03: tb(15, 3) = -1.5711092769E-06: tb(15, 4) = 1.9331004067E-06: tb(15, 5) = 0.806
    tb(16, 1) = -0.001523256792873: tb(16, 2) = 0.001002829043573: tb(16, 3) = -0.000015729785429: tb(16, 4) = 1.9354098768E-06: tb(16, 5) = 0.826
    tb(17, 1) = -1.3028125169482E-03: tb(17, 2) = 7.349000995177E-04: tb(17, 3) = -1.5748832546E-06: tb(17, 4) = 1.9377248718E-06: tb(17, 5) = 0.846
    tb(18, 1) = -1.1210535017199E-03: tb(18, 2) = 5.200950155166E-04: tb(18, 3) = -1.5764537128E-06: tb(18, 4) = 0.000001939580859: tb(18, 5) = 0.871
    tb(19, 1) = -9.335584519317E-04: tb(19, 2) = 3.048780487805E-04: tb(19, 3) = -1.5780737322E-06: tb(19, 4) = 0.000001941440405: tb(19, 5) = 0.896
    tb(20, 1) = -7.238306025284E-04: tb(20, 2) = 7.12601611711E-05: tb(20, 3) = -1.5798858504E-06: tb(20, 4) = 0.000001943458941: tb(20, 5) = 0.996
    tb(21, 1) = -9.082062326932E-04: tb(21, 2) = 2.563514599689E-04: tb(21, 3) = 7.4474093761E-06: tb(21, 4) = -7.1188764479E-06: tb(21, 5) = 9.999
    
    dT = tp - 20
    
    For x = 1 To 21
        If d20 <= tb(x, 5) Then Exit For
    Next
    
    fator = 1 + tb(x, 2) * dT + tb(x, 4) * dT ^ 2
    fator = fator + (tb(x, 1) * dT + tb(x, 3) * dT ^ 2) / d20
    fator = Int(fator * 10000 + 0.5) / 10000
    
    Fcv = fator
    Exit Function
FcvErro:
    Fcv = 0
End Function
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página