提问人:Muhammad Kafiansyah 提问时间:2/27/2023 最后编辑:KairuMuhammad Kafiansyah 更新时间:2/27/2023 访问量:96
VBA 运行时错误 62:输入文件末尾 - Excel VBA 到 HEC-RAS
VBA Run Time Error 62: Input Past End of File - Excel VBA to HEC-RAS
问:
我正在编写一个 txt 文件(.U04) 从带有 VBA 的 excel 到 HEC-RAS。我在下面使用了 3 个月的这段代码,没有问题。但突然在 2 月 4 日,代码被 击中。错误从 开始。run time error 62: Input past end of file
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
我已尝试更改 with 但仍然错误。Do While Not EOF(1)
Do Until EOF(1)
我希望有人能解决这个问题...... :)
答: 暂无答案
评论
Do While