Hallo Michi
Ich nochmal!
Ich habe die Lösung. Juhuuuuuuu!
Im Internet habe ich ein fertiges Programm gefunden. Ich habe zwar keine Ahnung, was da rumgerechnet wird, aber es klappt!
Hier mal der vollständige Code:
Private Sub Command1_Click()
Dim sFN As String
Dim sCap As String
Dim sFil As String
Dim rVal As Long
Dim Datei As String
Dim Wert As Double
sCap = "Kalibrierdaten importieren"
sFN = "KALIBRI.DAT"
sFil = "*.DAT (Daten)|*.DAT|*.* (Alle Dateien)|*.*"
rVal = VBEX_OpenFileDLG(sCap, sFN, App.Path, sFil, ".DAT", OFNFILEMUSTEXIST)
If rVal > 0 Then
Datei = Trim$(sFN)
Dim f As Long
Dim Satz As KalibrierDatenSatz
Dim i As Long
f = FreeFile
Open Datei For Binary As #f Len = Len(Satz)
While Not EOF(f)
Get #f, , Satz
i = i + 1
Debug.Print "sw:"; pasString2vbString(Satz.SW)
Debug.Print pasString2vbString(Satz.USp)
Debug.Print pasString2vbString(Satz.ISp)
Debug.Print pasString2vbString(Satz.UHs)
Debug.Print pasString2vbString(Satz.IHs)
Debug.Print Satz.Pol
Debug.Print "RV:"; Satz.RV; " - ";
RealConv Satz.RV, Wert
Debug.Print Wert
Debug.Print "f0:"; Satz.f0; " - ";
RealConv Satz.f0, Wert
Debug.Print Wert
Debug.Print "f1:"; Satz.f1; " - ";
RealConv Satz.f1, Wert
Debug.Print Wert
Debug.Print "f2:"; Satz.f2; " - ";
RealConv Satz.f2, Wert
Debug.Print Wert
Debug.Print "f3:"; Satz.f3; " - ";
RealConv Satz.f3, Wert
Debug.Print Wert
Debug.Print "fp:"; Satz.fp; " - ";
RealConv Satz.fp, Wert
Debug.Print Wert
Debug.Print pasString2vbString(Satz.Bem)
Debug.Print pasString2vbString(Satz.Res)
Wend
Close #f
End If
End Sub
Sub RealConv(Real$, NewCost#)
' create an array to hold each byte of the real string
Dim RealHold(6)
RealHold(1) = Asc(Mid$(Real$, 1, 1))
RealHold(2) = Asc(Mid$(Real$, 2, 1))
RealHold(3) = Asc(Mid$(Real$, 3, 1))
RealHold(4) = Asc(Mid$(Real$, 4, 1))
RealHold(5) = Asc(Mid$(Real$, 5, 1))
RealHold(6) = Asc(Mid$(Real$, 6, 1))
' if positive contains a number then its negative
positive = &H80 And RealHold(6)
' clear the Pos/Neg bit from byte 6
RealHold(6) = &H80 Or RealHold(6)
' set up the significand as 1.0
Significand# = 1#
' check each individual bit for on/off; if on then multiply out the
' number (2,4,8,16,32,64,128, etc.)
For bytecheck = 2 To 6
' bit 0 of byte
If (RealHold(bytecheck) And &H1) = 1 Then
Significand# = Significand# + power(2, (0 + (bytecheck - 2) * 8))
End If
' bit 1 of byte
If (RealHold(bytecheck) And &H2) = 2 Then
Significand# = Significand# + power(2, (1 + (bytecheck - 2) * 8))
End If
' bit 2 of byte
If (RealHold(bytecheck) And &H4) = 4 Then
Significand# = Significand# + power(2, (2 + (bytecheck - 2) * 8))
End If
' bit 3 of byte
If (RealHold(bytecheck) And &H8) = 8 Then
Significand# = Significand# + power(2, (3 + (bytecheck - 2) * 8))
End If
' bit 4 of byte
If (RealHold(bytecheck) And &H10) = 16 Then
Significand# = Significand# + power(2, (4 + (bytecheck - 2) * 8))
End If
' bit 5 of byte
If (RealHold(bytecheck) And &H20) = 32 Then
Significand# = Significand# + power(2, (5 + (bytecheck - 2) * 8))
End If
' bit 6 of byte
If (RealHold(bytecheck) And &H40) = 64 Then
Significand# = Significand# + power(2, (6 + (bytecheck - 2) * 8))
End If
' bit 7 of byte
If (RealHold(bytecheck) And &H80) = 128 Then
Significand# = Significand# + power(2, (7 + (bytecheck - 2) * 8))
End If
Next
' normalize the number by dividing calculated number by a number with all
' bits turned on: 2 to the power of 40
Significand# = Significand# / power(2, 40)
' calculate in the exponent
Number# = Significand# * power(2, (RealHold(1) - 128))
' set the pos/neg sign
If positive > 0 Then Number# = Number# * -1
NewCost# = Number#
End Sub
Function power#(x, y As Integer)
' simple x to the power of y function
power# = Exp(y * Log(x))
End Function Gruss Frank |