本人是個新手,需要做實驗,VB代碼如下:
SUB create()
Dim a(132) As String
Dim b(132) As String
Dim c(132) As String
Dim d(132) As String
Dim e(132) As String
Dim f(132) As String
Dim g(132) As String
Dim f1, f2 '定義地址串列
Dim nm As Integer
For nm = 2 To 133
Sheets("sheet1").Select
Range("A" & nm).Select
a(nm) = Selection.Value '陣列賦值,并確定引數形式
a(nm) = Format(a(nm), "0.00")
Range("B" & nm).Select
b(nm) = Selection.Value
b(nm) = Format(b(nm), "0.00")
Range("C" & nm).Select
c(nm) = Selection.Value
c(nm) = Format(c(nm), "0.00")
Range("D" & nm).Select
d(nm) = Selection.Value
d(nm) = Format(d(nm), "0.00")
Range("E" & nm).Select
e(nm) = Selection.Value
e(nm) = Format(e(nm), "0.00")
Range("F" & nm).Select
f(nm) = Selection.Value
f(nm) = Format(f(nm), "0.00")
Range("G" & nm).Select
g(nm) = Selection.Value
g(nm) = Format(g(nm), "0.00")
Next
Range("A248").Select '選取擬建模型地址存盤位置
For Index = 2 To 133
f1 = "F:\交叉口仿真\singal.inp" '讀取原始檔案
f2 = Selection.Value
Open f2 For Output As #2
Open f1 For Binary As #1
Do While Not EOF(1)
Line Input #1, vartemp
If InStr(1, vartemp, "accDecelOwn=""-1""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "accDecelOwn=""-1""", "accDecelOwn=" & """" & p(Index) & """")
End If
If InStr(1, vartemp, "diffusTm=""60""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "diffusTm=""60""", "diffusTm=" & """" & q(Index) & """")
End If
If InStr(1, vartemp, "lookAheadDistMax=""250""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "lookAheadDistMax=""250""", "lookAheadDistMax=" & """" & b(Index) & """")
End If
If InStr(1, vartemp, "maxDecelOwn=""-4""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "maxDecelOwn=""-4""", "maxDecelOwn=" & """" & n(Index) & """")
End If
If InStr(1, vartemp, "maxDecelTrail=""-3""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "maxDecelTrail=""-3""", "maxDecelTrail=" & """" & n(Index) & """")
End If
If InStr(1, vartemp, "minHdwy=""0.5""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "minHdwy=""0.5""", "minHdwy=" & """" & m(Index) & """")
End If
If InStr(1, vartemp, "safDistFactLnChg=""0.6""", vbTextCompare) > 0 Then
vartemp = Replace(vartemp, "safDistFactLnChg=""0.6""", "safDistFactLnChg=" & """" & r(Index) & """")
End If
Print #2, vartemp
Loop
Close #1
Close #2
ActiveCell.Offset(1, 0).Select
Next
MsgBox ("over!!")
End Sub
Sub simulation()
Dim Vissim As Vissim
Dim simulation As simulation
Dim simulationfile As String
Dim randomseed As Integer
Set Vissim = New Vissim
Set simulation = Vissim.simulation
Sheets("sheet1").Select
Range("A1").Select '儲存仿真檔案地址
While Selection <> ""
simulationfile = Selection.Value
Vissim.LoadNet simulationfile
Vissim.LoadLayout "singal.ini"
simulation.Speed = 0
simulation.randomseed = 120 '可以自動化實作
simulation.RunContinuous
ActiveCell.Offset(1, 0).Select
Wend
End Sub
uj5u.com熱心網友回復:
運行程式,看哪一行報錯,然后看那一行呼叫的函式或者方法的名字有沒有寫錯,或者函式有沒有定義。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/21773.html
標籤:VBA
上一篇:求助,用vba代碼控制滑鼠,用到mouseeventf_absolute在win10里不好用了是為什么呢
下一篇:小白遇到安裝問題
