Hallo Leute,
ich hoffe ihr könnt mir weiterhelfen. Ich schreibe mit einem c++-Programm kontinuierlich in eine Textdatei. Folgendes VBA-Sub soll mir die Daten dann zeilenweise auslesen und entsprechende Werte in Variablen übernehmen.
Der Code:
Sub ReadInUebergabe(ByVal TargetFileName As String, ByVal seperator As String, _
ByRef ResultArr() As Double)
'reads in the file line by line and delivers a double-array filled with the
' values behind seperator
'gives back a 1-D-Array include all values from Targetfile as double values
Dim InputData As String
Dim inthandle As Integer
Dim comma As String
Dim plus As String
Dim strresult As String
Dim result As Double
Dim counter As Long
Dim m As Integer
Dim n As Integer
Dim usecheck As Boolean
'initializes an 1-D-array typ double with heigth: numbvar
ReDim ResultArr(numbvar)
'fills the array with values
If TargetFileName <> "" Then
usecheck = True
Do Until usecheck = False 'do until the file is not used anymore by
' an other process
usecheck = FileInUse(TargetFileName)
Loop
inthandle = FreeFile
Open TargetFileName For Input As #inthandle
For n = 1 To (numbvar + 2)
Line Input #inthandle, InputData
If InStr(InputData, "abort-flag") <> 0 Then 'checks the file if
' abort-flag(global var.) is set_
AbortFlag = True 'in first
' input-line, then set functions_
Close #inthandle 'flag to true
Exit Sub
End If
If InStr(InputData, "start-flag") <> 0 Then 'checks the file if
' start-flag(global-var.) is set_
StartFlag = True 'in first
' input-line, then set functions_
Close #inthandle 'flag to true
Exit Sub
End If
' #eingefügt 17.9 anfang
If InStr(InputData, "countgen") <> 0 Then 'checks the file for
' the string countgen and puts the integer value
strresult = MyExtract(InputData, 2, "F", ":") 'to the global
' variable countgen
countgen = CInt(strresult)
Close #inthandle
GoTo EndForLoop
End If
If InStr(InputData, "countrun") <> 0 Then 'checks the file for
' the string countgen and puts the integer value
strresult = MyExtract(InputData, 2, "F", ":") 'to the global
' variable countgen
countrun = CInt(strresult)
Close #inthandle
GoTo EndForLoop
End If
' #eingefügt 17.9 anfang
strresult = MyExtract(InputData, 2, "F", seperator) 'extracts a
' stringvalue behind tab
comma = Replace(strresult, ".", ",") 'replaces the "." with an ","
plus = Replace(comma, "+", "") 'deletes the "+" sign in string
ResultArr(n) = CDbl(plus) 'converts the edited string into a double
'#eingefügt 17.9
EndForLoop:
Next n
Close #inthandle
Else: MsgBox "Datei nicht vorhanden"
End If
End Sub Wenn ich das Sub in meinem Hauptprogramm aufrufe und es steht nur start-flag in der besagten Datei funktioniert das Sub. Ebenso, wenn nur 2 Zahlenwerte untereinander stehen.
Sobald ich aber in der ersten Zeile countrun: 1 und in der 2. Zeile countgen: 1 bricht das Programm im 2. Durchlauf der For-Schleife mit dem o.g. Fehler ab. Die Datei existiert definitiv noch und inthandle ist auch noch 1.
Hat jemand eine Ahnung, ich nämlich nicht mehr ?
Viele Grüße
Guddy |