每一行都是一个中断对象,用户和OR运算符逻辑评估每行/中断对象的多个列值

时间:2017-11-16 20:43:09

标签: excel vba excel-vba object collections

我有以下条件,用户输入到Excel工作表上。我试图以一种将这些变量作为参数传递并对原始数据集进行排序的方式对用户输入进行编码。

 Field      Criteria I          Criteria II         Criteria III            Criteria IV     
MsgStr    Next    1008001 OR  Next    1002001 OR  Next 1003001 OR Next 1009001 AND    Next
PriceDiff >   -25.01  AND <   25.01   AND Next                        
AssetCUR  = AcctCUR   END

我已将用户输入编译为2D数组,其中每个字段MsgStr,条件1008001,运算符AndOR=,{{ 1}},<,在所有其他字段>

所有字段都是列标题,每个字段的条件是每个列中的单元格。在MOST,每个列只有一个字段,即每行将是Price Diff1008001。其他字段/列标题可能包含我需要评估的单元格,这些数量等于100xxxx或大于x > AND 小于{{1 }} -25但最多< PER ROW 只有一个值。每列下的所有标准都只有一个值。此中断的最后一个标准是此25列必须PriceDiffAssetCur此用户条件中不同列下相同行的值/货币, =必须<> AssetCUR

  • 换句话说,我觉得我可以更好地解释每一行是一个 会计中断或短中断对象所以我创建了一个 =我所有的Fields都是类变量,现在我需要 根据每个Row / Break对象评估变量WITHIN 值(AT MAX)每列PER下每个单元一个值 ROW / Break Object。

我有一个用于所有我的休息类别的2D字符串数组。位置(1,1)是中断类别 SMALL中断(1,1),然后在阵列的每个2D插槽中的第一列之后的所有列中跟随标准。 2D数组的目的就是这样我可以循环用户输入表并捕获数据。这是我捕获用户逻辑的更简单方法。 AcctCur(1,2)Break Class(1,3)SMALL BREAKS(1,4)MsgStr1

然后例如另一个Break Category将是(3,1) Cash Break Next(3,1)1008001 OR Next 1002001 OR Next 1003001 OR Next 1009001 AND Next PriceDiff > -25.01 AND < 25.01 AND Next AssetCUR = AcctCUR END (3,2)CASH(3,3)MsgStr

因此,每个中断类别都具有与中断类别相关联的用户逻辑我想在评估c中的数据时返回 如果行/中断对象等于这4个Next中的任何一个,1001000100 END位于MsgStringsPriceDiff内并且>-$25 {{1}这也等于<$25这个中断也EUR(但可能是JPY或USD)我需要编写代码来评估这个。

AssetCUR

这是我将Excel工作表转换为所有对象的位置:

AcctCUR

这是我的BeakInfo类模块:我仍然在学习对象和类,但正如你在上面看到的那样,我真的很想找到我的评估EACH ROW的头脑,这是一个BREAK OBJECT与多重评估同时存储USER INPUT CRITERIA,即在MULTIPLE和Values之间旋转时多个OR值。

  • 宏需要以用户灵活的方式实施 可以在任何字段列标题下指定和标准 使用运算符和字段列表的值。

  • 我在单独的工作表中列出了所有可能的用户标准 旨在标准化所有可能的运营商,逻辑和标准 用户可以输入。

  • 此帖子中的第一个代码片段代表我的核心代码,您可能会看到我奋力评估和存储多个用户条件。 我想也许我应该走向课程程序,如 Getters,Setters,Let Class Method?

    选项明确

    EUR

这是一张名为 Sub Implement_Mapping() Dim aMapRow As Integer, aMapCol As Integer Dim tempStrBreak As String Dim tempStrCrit As String Dim CurrentBreakCat As String Dim CurrentField As String Dim andFLAG As Boolean Dim ImplementBI As BreakInfo Dim ImplementObjLSL As Collection Dim qQueue As New queue Dim aResult As Variant Dim index As Long Dim vValue As Variant '''basic Queue Dim queueAND As Object Set ImplementObjLSL = New Collection For aMapRow = LBound(aLogic, 1) To UBound(aLogic, 1) For aMapCol = LBound(aLogic, 2) To UBound(aLogic, 2) If IsInArrayByVal(aLogic(aMapRow, aMapCol), Break_List) = True Then CurrentBreakCat = aLogic(aMapRow, aMapCol) Set ImplementBI = New BreakInfo aMapCol = aMapCol + 1 Else aMapCol = aMapCol + 1 End If greaterTHAN = False lessTHAN = False eqEQUALS = False noEQUALS = False If IsInArrayByVal(aLogic(aMapRow, aMapCol), Field_List) = True Then CurrentField = aLogic(aMapRow, aMapCol) aMapCol = aMapCol + 1 End If If (aLogic(aMapRow, aMapCol) <> "" And aLogic(aMapRow, aMapCol) <> "Next") Then If IsInArrayByVal(aLogic(aMapRow, aMapCol), Operator_List) = True Then Select Case aLogic(aMapRow, aMapCol) Case "<" lessTHAN = True aMapCol = aMapCol + 1 Case ">" greaterTHAN = True aMapCol = aMapCol + 1 Case "<>" noEQUALS = True aMapCol = aMapCol + 1 Case "=" eqEQUALS = True aMapCol = aMapCol + 1 End Select ElseIf aLogic(aMapRow, aMapCol) = "OR" Then Do While aLogic(aMapRow, aMapCol) <> "AND" If (aLogic(aMapRow, aMapCol) <> "Next" And aLogic(aMapRow, aMapCol) <> "OR") Then Debug.Print aLogic(aMapRow, aMapCol) qQueue.Enqueue aLogic(aMapRow, aMapCol) End If aMapCol = aMapCol + 1 Debug.Print aLogic(aMapRow, aMapCol) Loop GoTo HereSkipII ElseIf aLogic(aMapRow, aMapCol) = "AND" Then andFLAG = True GoTo HereSkip End If Select Case CurrentField Case "AcctCUR" ImplementBI.AcctCUR = aLogic(aMapRow, aMapCol) Case "AssetCur" ImplementBI.AssetCUR = aLogic(aMapRow, aMapCol) Case "AssetID" ImplementBI.AssetID = aLogic(aMapRow, aMapCol) Case "Coupon" ImplementBI.Coupon = aLogic(aMapRow, aMapCol) Case "EntityID" ImplementBI.EntityID = aLogic(aMapRow, aMapCol) Case "EntityName" ImplementBI.EntityName = aLogic(aMapRow, aMapCol) Case "InvType" ImplementBI.InvType = aLogic(aMapRow, aMapCol) Case "IssueDes" ImplementBI.IssueDes = aLogic(aMapRow, aMapCol) Case "IssueName" ImplementBI.IssueName = aLogic(aMapRow, aMapCol) Case "LedgAcctDes" ImplementBI.LedgAcctDes = aLogic(aMapRow, aMapCol) Case "LedgerAMT" ImplementBI.LedgerAMT = aLogic(aMapRow, aMapCol) Case "LngSht" ImplementBI.LngSht = aLogic(aMapRow, aMapCol) Case "MatDate" ImplementBI.MatDate = aLogic(aMapRow, aMapCol) Case "MsgStr" ImplementBI.MsgStr = aLogic(aMapRow, aMapCol) Case "NetAMTL" ImplementBI.NetAMTL = aLogic(aMapRow, aMapCol) Case "PAID" ImplementBI.PAID = aLogic(aMapRow, aMapCol) Case "PAIDType" ImplementBI.PAIDType = aLogic(aMapRow, aMapCol) Case "PriceDiff" If ImplementBI.PriceDiff = 0 Then 'If IsEmpty(ImplementBI.PriceDiff) = False Then ImplementBI.PriceDiff = aLogic(aMapRow, aMapCol) ElseIf (ImplementBI.PriceDiff <> 0 And ImplementBI.PriceDiff2 = 0) Then ImplementBI.PriceDiff2 = aLogic(aMapRow, aMapCol) ElseIf (ImplementBI.PriceDiff2 <> 0 And ImplementBI.PriceDiff2 <> 0) Then ImplementBI.PriceDiff3 = aLogic(aMapRow, aMapCol) 'Set queueAND = CreateObject("System.Collections.Queue") 'queueAND.Enqueue aLogic(aMapRow, aMapCol) End If Case "PST" ImplementBI.PST = aLogic(aMapRow, aMapCol) Case "RowNo" ImplementBI.RowNo = aLogic(aMapRow, aMapCol) Case "RuleID" ImplementBI.RuleID = aLogic(aMapRow, aMapCol) Case "Sector" ImplementBI.Sector = aLogic(aMapRow, aMapCol) Case "SecurityType" ImplementBI.SecurityType = aLogic(aMapRow, aMapCol) Case "ShareClass" ImplementBI.ShareClass = aLogic(aMapRow, aMapCol) Case "SrcDes" ImplementBI.SrcDes = aLogic(aMapRow, aMapCol) Case "SubSecType" ImplementBI.SubSecType = aLogic(aMapRow, aMapCol) Case "UpDate" ImplementBI.UpDate = aLogic(aMapRow, aMapCol) Case "ValDate" ImplementBI.ValDate = aLogic(aMapRow, aMapCol) End Select HereSkip: End If aMapCol = aMapCol + 1 Debug.Print aLogic(aMapRow, aMapCol) Loop HereSkipII: Next aMapCol Next aMapRow End Sub 的工作表,标准化所有潜在的用户输入:

Sub Fill_LSL_Objects()
Dim aMrow As Integer, aMcol As Integer

Dim BI As BreakInfo
Dim ObjLSL As Collection

Dim key As Long


    Set ObjLSL = New Collection

For aMrow = LBound(aMRecon, 1) To UBound(aMRecon, 1)
    For aMcol = LBound(aMRecon, 2) To UBound(aMRecon, 2)

                If aMcol = 2 And aMrow > 1 Then

                    Set BI = New BreakInfo

                    BI.EntityID = CStr(aMRecon(aMrow, aMcol))
                    BI.ShareClass = aMRecon(aMrow, aMcol + 1)
                    BI.Sector = aMRecon(aMrow, aMcol + 2)
                    BI.AssetID = aMRecon(aMrow, aMcol + 3)
                    BI.AcctCUR = aMRecon(aMrow, aMcol + 5)
                    BI.IssueName = aMRecon(aMrow, aMcol + 6)
                    BI.PAID = aMRecon(aMrow, aMcol + 7)
                    BI.AssetCUR = aMRecon(aMrow, aMcol + 8)
                    BI.ValDate = aMRecon(aMrow, aMcol + 9)
                    BI.LedgerAMT = aMRecon(aMrow, aMcol + 10)
                    BI.NetAMTL = aMRecon(aMrow, aMcol + 11)
                    BI.PriceDiff = aMRecon(aMrow, aMcol + 14)
                    BI.RuleID = aMRecon(aMrow, aMcol + 15)
                    BI.SrcDes = aMRecon(aMrow, aMcol + 17)
                    BI.MsgStr = aMRecon(aMrow, aMcol + 18)
                    BI.UpDate = aMRecon(aMrow, aMcol + 20)
                    BI.LngSht = aMRecon(aMrow, aMcol + 25)
                    BI.PAIDType = aMRecon(aMrow, aMcol + 41)
                    BI.Coupon = aMRecon(aMrow, aMcol + 42)
                    BI.MatDate = aMRecon(aMrow, aMcol + 43)
                    BI.SecurityType = aMRecon(aMrow, aMcol + 44)
                    BI.InvType = aMRecon(aMrow, aMcol + 45)
                    BI.PST = aMRecon(aMrow, aMcol + 46)
                    BI.IssueDes = aMRecon(aMrow, aMcol + 48)
                    BI.SubSecType = aMRecon(aMrow, aMcol + 58)
                    BI.EntityName = aMRecon(aMrow, aMcol + 59)
                    BI.LedgAcctDes = aMRecon(aMrow, aMcol + 62)
                    BI.RowNo = aMrow


                    key = key + 1
                    ObjLSL.Add BI, CStr(key)

                End If
        Next aMcol


    Next aMrow

    xrow = 0
    Dim Break As Object

        For Each Break In ObjLSL

           If (Break.MsgStr = 1008001 Or Break.MsgStr = 1002001 Or Break.MsgStr = 1003001 Or Break.MsgStr = 1009001) And _
            (Break.PriceDiff > -25.01 And Break.PriceDiff < 25.01) And _
            (StrComp(Break.AssetCUR, Break.AcctCUR, vbTextCompare) = 0) Then

                aTab(Break.RowNo, 1) = "SMALL BREAKS"
'                aTab(Break.RowNo, 2) = Break.RowNo
'                aTab(Break.RowNo, 3) = Break.AssetCUR
'                aTab(Break.RowNo, 4) = Break.AcctCUR
'                aTab(Break.RowNo, 5) = Break.PriceDiff
'                aTab(Break.RowNo, 6) = Break.MsgStr
                'xrow = 1
                xrow = xrow + 1
'                aTab(xrow, 1) = "SMALL BREAKS"
'                aTab(xrow, 2) = Break.RowNo
'                aTab(xrow, 3) = Break.AssetCUR
'                aTab(xrow, 4) = Break.AcctCUR
'                aTab(xrow, 5) = Break.PriceDiff
'                aTab(xrow, 6) = Break.MsgStr
                '''Debug.Print Break.EntityID

            End If


        Next



End Sub

0 个答案:

没有答案