VBA Run Time Error 62: Input Past End of File - Excel VBA to HEC-RAS

115 views Asked by At

I was writing a txt file (.U04) from excel with VBA to HEC-RAS. I was use this code below for 3 months and there was no problem. But suddenly on February 4 the code was hit by run time error 62: Input past end of file. The error start from line 44 : Line Input #1, strLine: Print #2, strLine_new_3.

Option Explicit

Sub newflowuns()


Dim HRC As New HECRASController
Dim strRASProject As String
strRASProject = "C:\Users\kom3\Documents\PADOLO\RAS_PADOLO_1D.prj"
HRC.Project_Open strRASProject

Dim strLine As String
Dim strPlanfile As String
Dim strNewPlanfile As String
Dim strFlowfile As String
Dim strNewFlowfile As String
Dim sngInflow As Single
Dim strLine_new_1 As String
Dim strLine_new_2 As String
Dim strLine_new_3 As String
Dim strLine_new_head As String
Dim strLine_old_head As String

strPlanfile = "C:\Users\kom3\Documents\PADOLO\RAS_PADOLO_1D.p14"
strNewPlanfile = "C:\Users\kom3\Documents\PADOLO\RAS_PADOLO_1D.tempp14"
strFlowfile = "C:\Users\kom3\Documents\PADOLO\RAS_PADOLO_1D.u04"
strNewFlowfile = "C:\Users\kom3\Documents\PADOLO\RAS_PADOLO_1D.tempu04"

Open strFlowfile For Input As #1
Open strNewFlowfile For Output As #2

strLine_old_head = "Flow Hydrograph= " & Sheet2.Range("CK2").Value
strLine_new_head = "Flow Hydrograph= " & Sheet2.Range("CJ2").Value

strLine_new_1 = Sheet2.Range("CJ4").Value
strLine_new_2 = Sheet2.Range("CK4").Value
strLine_new_3 = Sheet2.Range("CL4").Value

Do While Not EOF(1)
    Line Input #1, strLine
    If InStr(strLine, strLine_old_head) Then
        Line Input #1, strLine: Print #2, strLine_new_head
        Line Input #1, strLine: Print #2, strLine_new_1
        Line Input #1, strLine: Print #2, strLine_new_2
        Line Input #1, strLine: Print #2, strLine_new_3
    Else
        Print #2, strLine
    End If
Loop

Close #1
Close #2


FileCopy strNewFlowfile, strFlowfile
Kill strNewFlowfile
HRC.QuitRas

Sheet2.Range("CK2") = Sheet2.Range("CJ2").Value 'NILAI SEBELUMNYA

End Sub

I have try to change the Do While Not EOF(1) with Do Until EOF(1) but still error.

I hope someone can solve this... :)

0

There are 0 answers