Home > Software engineering >  Vb s type thermocouple inverse function with d1 is no problem, when d2/d3, d4 calculated number and
Vb s type thermocouple inverse function with d1 is no problem, when d2/d3, d4 calculated number and

Time:09-22

 Function SVtoTemp As Double (V) As a Double 'V for the mV unit voltage switch S type thermocouple temperature inverse Function 

'(235 ~ 1874) mv
Dim d1 (10) As a Double
D1 (0)=0
D1 (1)=0.18494946
D1 (2)=0.0000800504062
D1 (3)=0.00000010223743
D1 (4)=1.52248592 e-10
D1 (5)=1.88821343 e-13
D1 (6)=1.59085941 e-16
D1 (7)=8.2302788 e-20
D1 (8)=2.34181944 e-23
D1 (9)=2.7978626 e-27


'(1874 ~ 10332)
Dim d2 (10) As a Double
D2 (0)=1.291507177
D2 (1)=0.1466298863
D2 (2)=0.00001534713402
(3)=3.145945973 d2 e-09
(4)=4.163257839 d2 e-13
D2 (5)=3.187863771 e-17
D2 (6)=1.2916375 e-21
D2 (7)=2.183475087 e-26
D2 (8)=1.447379511 e-31
D2 (9)=8.211272125 e-36


'(10332 ~ 17536)
Dim d3 (6) As a Double
D3 (0)=8.087801117
D3 (1)=0.1621573104
D3 (2)=0.000008536869453
D3 (3)=4.719686976 e-10
D3 (4)=1.441693666 e-14
D3 (5)=2.08161889 e-19
'(17536 ~ 18694)
Dim d4 (5) As a Double
D4 (0)=53338.75126
D4 (1)=1.235892298
D4 (2)=0.001092657613
D4 (3)=4.265693686 e-08
D4 (4)=6.24720542 e-13

Dim Temp As Double
Temp=0

If V & lt; Then 1874
For I=0 To 9
Temp=Temp + d1 (I) * V ^ I
Next
ElseIf V & gt;=1874 And V & lt; Then 10332
For I=0 To 9
Temp=Temp + d2 (I) * V ^ I
Next
ElseIf V & gt;=10332 And V & lt; Then 17536


For I=0 To 5
Temp=Temp + d3 (I) * V ^ I
Next

ElseIf V & gt; Then=17536
For I=0 To 4
Temp=Temp + d4 (I) * V ^ I
Next

End the If
SVtoTemp=Temp
End the Function

CodePudding user response:

Check your table of constants, multi-purpose several benchmark comparison thermometer,

Give you another style code,
 
Dim d (9) As a Double
Dim As Integer I

As a Double Function SVtoTemp (V) As a Double
Dim Temp As Double

If (V & lt; - 235) Or (V & gt; 18694) Then the Exit Function

If V & lt; Then 1874
D (0)=0
D (1)=0.18494946
D (2)=0.0000800504062
D (3)=0.00000010223743
D (4)=1.52248592 e-10
D (5)=1.88821343 e-13
D (6)=1.59085941 e-16
D (7)=8.2302788 e-20
D=2.34181944 (8) e-23
D (9)=2.7978626 e-27
ElseIf (V & gt;=1874) And (V & lt; 10332) Then
D (0)=1.291507177
D (1)=0.1466298863
D (2)=0.00001534713402
D (3)=3.145945973 e-09
D (4)=4.163257839 e-13
D (5)=3.187863771 e-17
D (6)=1.2916375 e-21
D (7)=2.183475087 e-26
D=1.447379511 (8) e-31
D=8.211272125 (9) e-36
ElseIf (V & gt;=10332) And (V & lt; 17536) Then
D (0)=8.087801117
D (1)=0.1621573104
D (2)=0.000008536869453
D (3)=4.719686976 e-10
D (4)=1.441693666 e-14
D (5)=2.08161889 e-19
D (6)=0
The Else
D (0)=53338.75126
D (1)=1.235892298
D (2)=0.001092657613
D (3)=4.265693686 e-08
D (4)=6.24720542 e-13
D (5)=0
End the If

For I=0 To 9
If (I & gt; (I)=0, 0) And (d) Then the Exit For
Temp=Temp + d (I) * V ^ I
Next I

SVtoTemp=Temp
End the Function

CodePudding user response:

Code of # 1 and the operation process of debug output
 
Sub Main ()
SVtoTemp 1000
SVtoTemp 10000
SVtoTemp 15000
SVtoTemp 18000
End Sub

As a Double Function SVtoTemp (V) As a Double
Dim d (9) As a Double
Dim As Integer I
Dim Temp As Double
Dim lMax As Long

If (V & lt; - 235) Or (V & gt; 18694) Then the Exit Function

The Debug. Print "==" & amp; V & amp; "=="
If V & lt; Then 1874
LMax=9
D (0)=0
D (1)=0.18494946
D (2)=0.0000800504062
D (3)=0.00000010223743
D (4)=1.52248592 e-10
D (5)=1.88821343 e-13
D (6)=1.59085941 e-16
D (7)=8.2302788 e-20
D=2.34181944 (8) e-23
D (9)=2.7978626 e-27
ElseIf (V & lt; 10332) Then
LMax=9
D (0)=1.291507177
D (1)=0.1466298863
D (2)=0.00001534713402
D (3)=3.145945973 e-09
D (4)=4.163257839 e-13
D (5)=3.187863771 e-17
D (6)=1.2916375 e-21
D (7)=2.183475087 e-26
D=1.447379511 (8) e-31
D=8.211272125 (9) e-36
ElseIf (V & lt; 17536) Then
LMax=6
D (0)=8.087801117
D (1)=0.1621573104
D (2)=0.000008536869453
D (3)=4.719686976 e-10
D (4)=1.441693666 e-14
D (5)=2.08161889 e-19
D (6)=0
The Else
LMax=5
D (0)=53338.75126
D (1)=1.235892298
D (2)=0.001092657613
D (3)=4.265693686 e-08
D (4)=6.24720542 e-13
D (5)=0
End the If

For I=0 To lMax
Temp=Temp + d (I) * V ^ I
The Debug. Print the I & amp; ":" & amp; Temp
Next I

SVtoTemp=Temp
End the Function

Below is the output, because the precision of reason, d3/d4 last step operation has no influence on the results
==1000==
0:0
1:184.94946
2:104.8990538
3:207.1364838
4:54.8878918
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related