⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccmdlookup.cls

📁 Data monkey是一个强大的是数据传输和转换应用程序。使用DataMonkey用户可以把复杂的文本文件格式
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CCmdLookup"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
' DataMonkey Data Conversion Application. Written by Theodore L. Ward
' Copyright (C) 2002 AstroComma Incorporated.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation; either version 2
' of the License, or (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
' The author may be contacted at:
' TheodoreWard@Hotmail.com or TheodoreWard@Yahoo.com

Option Explicit
Option Base 0

Private mIndex As Integer
Private mUniqueID As String
Private mLookupTable
Private mNumElements As Integer

Public Function GetElements(El As Integer, Lookup As Variant, ConvertTo As Variant) As Boolean
    
    If El >= mNumElements Or El < 0 Then
        GetElements = False
        Exit Function
    End If
    
    GetElements = True
    Lookup = mLookupTable(0, El)
    ConvertTo = mLookupTable(1, El)

End Function

Public Function DeleteRow(row As Integer) As Boolean
    
    Dim i As Integer, j As Integer

    If row < 0 Or row >= mNumElements Then
        DeleteRow = False
        Exit Function
    End If
    
    mNumElements = mNumElements - 1

    'Shift the data in the array
    For i% = index To mNumElements - 1
        For j% = 0 To 2 - 1
            mLookupTable(j%, i%) = mLookupTable(j%, i% + 1)
        Next j%
    Next i%

End Function

Public Function GetNumElements() As Integer
    GetNumElements = mNumElements
End Function

Public Function SetElement(Column As Integer, index As Integer, newVal As Variant) As Boolean
    On Error GoTo eHandler
    SetElement = False
    If Column < 0 Or Column > 1 Then Exit Function
    If index > mNumElements Or index < 0 Then Exit Function
    
    EnsureSpaceFor index
    mLookupTable(Column, index) = newVal
    If index = mNumElements Then mNumElements = mNumElements + 1
    SetElement = True
    Exit Function
eHandler:
End Function

Private Sub EnsureSpaceFor(index As Integer)
    If index > UBound(mLookupTable, 2) Then
        ReDim Preserve mLookupTable(2, index + 10)
    End If
End Sub

Public Function GetElement(Column As Integer, index As Integer) As Variant
    GetElement = mLookupTable(Column, index)
End Function

Public Function InitializeLookupTable(lut, cnt As Integer)
    
    ' Make sure we have enough space to store our items.
    EnsureSpaceFor cnt
    
    ' Store the items.
    For mNumElements = 0 To cnt - 1
        mLookupTable(0, mNumElements) = lut(0, mNumElements)
        mLookupTable(1, mNumElements) = lut(1, mNumElements)
    Next
    
End Function

Public Function AddLookup(Lookup As Variant, ConvertTo As Variant)
    
    ' Make sure the new items will fit.
    EnsureSpaceFor mNumElements

    ' Store the new values in the lookup table.
    mLookupTable(0, mNumElements) = IIf(IsNull(Lookup), "", Lookup)
    mLookupTable(1, mNumElements) = IIf(IsNull(ConvertTo), "", ConvertTo)
    
    ' Increment the count.
    mNumElements = mNumElements + 1
    
End Function

Public Function GetID() As String
    GetID = mUniqueID
End Function

Public Function Copy() As CCmdLookup
    On Error GoTo eHandler
    Set Copy = Nothing

    Dim newObj As CCmdLookup
    Set newObj = New CCmdLookup
    
    newObj.InitializeLookupTable mLookupTable, mNumElements
    
    Set Copy = newObj
    Set newObj = Nothing
    Exit Function

eHandler:
    LogError "CCmdLookup", "Copy", Error(Err), False

End Function

Public Function GetSpecificDescription() As String
    Dim x As String
    x = "Look for this value in a conversion table"
    GetSpecificDescription = x

End Function

Public Function GetApplications() As eCmdApplications
    GetApplications = GCmdHelper.CMDGetApplications(CmdType())
End Function

Public Function EditProperties(NameForCaption As String, Optional ByRef Import As CImport = Nothing) As Integer
    Dim tImport As CImport
    Set tImport = Import
    If tImport Is Nothing Then Set tImport = GImport
    
    frmCMDLookupTableProperties.Initialize Me, NameForCaption
    frmCMDLookupTableProperties.Show vbModal
    
    EditProperties = GFormReturnValue

End Function

Public Function CmdType() As Integer
    CmdType = eCmdTypes.cmdLookup
End Function

Public Property Let index(ByVal vData As Integer)
    mIndex = vData
End Property

Public Property Get index() As Integer
    index = mIndex
End Property

Public Function Execute(ByRef value As Variant, Optional CnvType As Integer = -1) As Boolean
    Dim i As Integer
    Execute = True
    
    ' Look for the item in question.
    For i = 0 To mNumElements - 1
        If mLookupTable(0, i) = value Then
            ' Change the value to the conversion value.
            value = mLookupTable(1, i)
            Exit Function
        End If
    Next i
    
    Execute = False
End Function
Public Function Load(arc As CArchive) As Boolean

    On Error GoTo eHandler
    
    Load = False
    Dim item As String, value As Variant, retVal As Integer
    
    '***************************************
    ' Get the next line from the input file.
    '***************************************
    
    Do
        retVal = arc.GetNextItem(item, value)
        
        ' Error, log it, then exit with error.
        If retVal = ArcRetType.cERROR Then
            arc.AddError
            GoTo done
            
        ' We are done with this object, leave.
        ElseIf retVal = ArcRetType.cENDITEM Then
            Exit Do
        End If
        
        Select Case item
            Case "INDEX"
                mIndex = value
            Case "NUMELEMENTS"
                ReDim mLookupTable(2, value)
            Case "LOOKUP"
                SetElement 0, mNumElements, value
            Case "CONVERTO"
                ' SetElement above should Increment the
                ' mNumelements counter. So we want to subtract one.
                SetElement 1, mNumElements - 1, value
            Case Else
            
                '*****************************************
                ' This line contains an unrecognized item.
                '*****************************************
                
                arc.AddError
                
        End Select
    Loop While True
    
    Load = True
done:
    Exit Function
    
eHandler:
    LogError "CCmdLookup", "Load", Error(Err)
    Exit Function

End Function
Public Function Save(arc As CArchive) As Boolean
    
    On Error GoTo eHandler
    Dim i As Integer
    
    Save = False

    arc.SaveItem aiBEGINACTION, GCmdHelper.GetName(CmdType())
    arc.SaveItem aiVALUE, "INDEX", mIndex
    arc.SaveItem aiVALUE, "NUMELEMENTS", mNumElements
    For i = 0 To mNumElements - 1
        arc.SaveItem aiVALUE, "LOOKUP", mLookupTable(0, i)
        arc.SaveItem aiVALUE, "CONVERTO", mLookupTable(1, i)
    Next i
    
    arc.SaveItem aiENDITEM, GCmdHelper.GetName(CmdType())
    
    Save = True
    Exit Function
    
eHandler:
    LogError "CCmdLookup", "Save", Error(Err)
    Exit Function
    
End Function

Private Sub Class_Initialize()
    mUniqueID = GetUniqueID
    ReDim mLookupTable(2, 10)
    mNumElements = 0
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -