|
'按我理解的取反,如果仅为取负自己修改一下,已做注释
'有问题留言
Option Explicit
Sub test()
Dim arr, pth, i, j, k, n, brr, crr, ii, m
pth = ThisWorkbook.Path & "\"
With Sheets("底盘工况")
brr = Range("f20:r20" & .Cells(Rows.Count, "f").End(xlUp).Row)
End With
Open pth & "event.aci" For Input As #1
crr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
For ii = 1 To UBound(brr, 1)
If Len(brr(ii, 1)) Then
arr = crr: m = m + 1: n = 0
For i = 0 To UBound(crr)
n = n + 1
If n + 1 > UBound(brr, 2) Then Exit For
For j = i To UBound(crr)
If InStr(arr(j), "ACT_" & n) Then
For k = j To UBound(crr)
If InStr(arr(k), "INPUT") Then
If Len(brr(ii, n + 1)) > 0 Then
If (n + 1) Mod 3 = 0 Then brr(ii, n + 1) = -1 * brr(ii, n + 1)
' 这是取反(原来为负变为正),或者改为取负 -1 * abs(brr(ii, n + 1))
arr(k) = Replace(arr(k), "0", brr(ii, n + 1))
End If
j = UBound(crr): i = k: Exit For
End If
Next
End If
Next j, i
Open pth & "event" & m & ".aci" For Output As #1
Print #1, Join(arr, vbNewLine)
Close #1
End If
Next
End Sub |
|