是否可以根据变量名选择要填充的数组?
我有4组属于黄色,蓝色,绿色和丁香的数据我创建了4个完全相同的数组。数据是相同的,除了它在开始时有Y,B,G或L,我想填充相应的数组,但不想创建4组。
For i = 0 To UBound(myLines)
myAlrmStrDate = Mid(myLines(i), 6, 2) & "/" & Mid(myLines(i), 4, 2) & "/" & Mid(myLines(i), 2, 2)
myAlrmStrTime = Mid(myLines(i), 9, 2) & ":" & Mid(myLines(i), 11, 2) & ":" & Mid(myLines(i), 13, 2)
myAlrmEndDate = Mid(myLines(i), 38, 2) & "/" & Mid(myLines(i), 36, 2) & "/" & Mid(myLines(i), 34, 2)
myAlrmEndTime = Mid(myLines(i), 41, 2) & ":" & Mid(myLines(i), 43, 2) & ":" & Mid(myLines(i), 45, 2)
myFaultDesc = (Mid(myLines(i), 49, 50))
mySorter = (Mid(myLines(i), 53, 1))
myCtime = CDate(myAlrmStrTime)
myMinutes = Hour(myCtime) * 3600 + Minute(myCtime) * 60 + Second(myCtime)
myftime = Int(myMinutes / 900) * 900
myftime = myftime / 86400 * 96
' Find IOTT Alarms
If InStr(1, (Mid(myLines(i), 49, 50)), "IOTT") And InStr(1, (Mid(myLines(i), 49, 50)), "CSC ack") <> 0 Then
myTimeDiff = CDate(myAlrmEndTime) - CDate(myAlrmStrTime)
mySorter(myftime).IOTT = mySorter(myftime).IOTT + 1
mySorter(myftime).IOTTDUR = mySorter(myftime).IOTTDUR + myTimeDiff
mySorter(96).IOTT = mySorter(96).IOTT + 1
If mySorter(myftime).IOTT > mySorter(98).IOTT Then
mySorter(97).IOTT = myftime
mySorter(98).IOTT = mySorter(myftime).IOTT
End If
MsgBox "Line" & "=" & i & myFaultDesc
End If
在上面的代码中,mySorter = (Mid(myLines(i), 53, 1))
行选择了Y,B,G或L,然后我想设置用于开始填充数组的数组。
基本上我希望它指向下面的数组,但不想创建复杂的if语句等
Y(myftime).IOTTDUR
B(myftime).IOTTDUR
G(myftime).IOTTDUR
L(myftime).IOTTDUR
my Current Array设置如下
Type Sorter
Date As Date
time As Date
Colour As Long
Area As String
Cart As Long
ISD As Long
WNI As Long
WNIDUR As Date
LM As Long
IOTT As Long
IOTTDUR As Date
IOC As Long
End Type
Global Y() As Sorter
Global G() As Sorter
Global B() As Sorter
Global L() As Sorter
Global YGBL() As Sorter
ReDim Y(99)
ReDim G(99)
ReDim B(99)
ReDim L(99)
ReDim YGBL(99, 4)
YGBL是建议添加的,但仍在研究如何运作
由于
答案 0 :(得分:0)
您可以创建一个多维数组,其中一个维度对应于颜色。您可以使用以下指令确定第一个维度的索引
colind=instr("YBGL",mysorter)
如果您的多维数组的名称是YBGL,那么您可以使用,例如您提到
YBGL(colind,myftime).IOTTDUR