VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "cTime" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Objeto responsável por armazenar tempo ou duração (mm:ss.xx) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Guarda o nome do objeto Private Const ST_MY_NAME As String = "cTime" ' Guarda o tempo (em milésimos) Private ln_Time As Long ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Retorna a comparação deste objeto com outro ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Function Compare(Value) As COMPARATION ' Vefica se tempo é igual If (Time = Value.Time) Then ' Retorna que é igual Compare = cEqual Else ' Verifica se é maior If (Time > Value.Time) Then ' Retorna que é maior Compare = cBigger Else ' Retorna que é menor Compare = cSmaller End If End If End Function Public Function LongCompare(lnValue As Long) As COMPARATION ' Vefica se tempo é igual If (Time = LongCompare) Then ' Retorna que é igual LongCompare = cEqual Else ' Verifica se é maior If (Time > lnValue) Then ' Retorna que é maior LongCompare = cBigger Else ' Retorna que é menor LongCompare = cSmaller End If End If End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedade em milisegundos ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get Time() As Long ' Retorna Time = ln_Time End Property Public Property Let Time(lnInput As Long) ' Seta ln_Time = lnInput End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedade em segundos ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get Seconds() As Long ' Retorna Seconds = Int(Time / LN_SECONDS) End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Guarda um tempo ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub setTime(lnMinutes As Long, lnSeconds As Long, lnMiliseconds As Long, blNegative As Boolean) ' Multiplica e soma Time = (lnMinutes * LN_MINUTES) + (lnSeconds * LN_SECONDS) + lnMiliseconds ' Se for negativo If blNegative Then ' Transforma em negativo Time = 0 - Time End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Retorna ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub GetTime(lnMinutes As Long, lnSeconds As Long, lnMiliseconds As Long, blNegative As Boolean) Dim lnAux As Long ' Inicia valores lnMinutes = 0 lnSeconds = 0 lnMiliseconds = 0 blNegative = False ' Se timer for inválido If (ln_Time = LN_INVALID_VALUE) Then ' Interrompe Exit Sub End If ' Se tempo for negativo If (ln_Time < 0) Then ' Guarda time em auxiliar lnAux = Abs(ln_Time) ' Seta que é negativo blNegative = True Else ' Guarda time em auxiliar lnAux = ln_Time ' Seta que é positivo blNegative = False End If ' Seta quantos minutos há lnMinutes = Int(lnAux / LN_MINUTES) ' Retira os minutos lnAux = lnAux - (lnMinutes * LN_MINUTES) ' Seta quantos segundos há lnSeconds = Int(lnAux / LN_SECONDS) ' Retira os segundos, o que sobrou são os milisegundos lnMiliseconds = lnAux - (lnSeconds * LN_SECONDS) End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedade em texto ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get text() As String Dim stAux As String Dim lnMM As Long Dim lnSS As Long Dim lnXX As Long Dim blNegative As Boolean ' Pega valores GetTime lnMM, lnSS, lnXX, blNegative ' Se for negativo If blNegative Then ' Inicia retorno com negativo text = "-" Else ' Inicia retorno com positivo text = ST_INVALID_VALUE End If ' Coloca minutos no auxiliar stAux = CStr(lnMM) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_SECONDS_SIZE) stAux = "0" + stAux Wend ' Adiciona ao rertorno text = text + stAux ' Coloca segundos no auxiliar stAux = CStr(lnSS) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_MINUTES_SIZE) stAux = "0" + stAux Wend ' Adiciona ao rertorno text = text + CH_MINUTE_SEP + stAux ' Coloca milisegundos no auxiliar stAux = CStr(lnXX) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_MILISECONDS_SIZE) stAux = "0" + stAux Wend ' Adiciona ao rertorno text = text + CH_SEC_SEP + stAux End Property Public Property Let text(stInput As String) On Error GoTo ErrTreat: ' Se for apenas números If IsNumeric(stInput) Then ' Seta valor direto ln_Time = CLng(stInput) Else Dim lnMM As Long, lnSS As Long, lnXX As Long Dim vtitN(1) As Long Dim blNegative As Boolean ' Inicia variáveis blNegative = False vtitN(1) = 1 ' Verifica qual o primeiro caracter Select Case Mid(stInput, 1, 1) ' Se for indicador de negativo Case "-" ' Seta negativo blNegative = True ' Reposiciona início vtitN(1) = 2 ' Se for indicador de positivo Case "+" ' Seta positivo blNegative = False ' Reposiciona início vtitN(1) = 2 End Select ' Pega a posição do primeiro separador (minutos) vtitN(0) = InStr(vtitN(1), stInput, CH_MINUTE_SEP) ' Verifica se encontrou If (vtitN(0)) > 0 Then ' Lê minutos lnMM = CInt(Mid(stInput, vtitN(1), vtitN(0) - vtitN(1))) ' Pega a posição do segundo separador (segundos) vtitN(1) = InStr(vtitN(0), stInput, CH_SEC_SEP) ' Verifica se encontrou If (vtitN(1) > 0) Then ' Lê segundos lnSS = CInt(Mid(stInput, vtitN(0) + 1, vtitN(1) - vtitN(0) - 1)) ' Verifica quantos caracteres sobraram Select Case (Len(stInput) - vtitN(1)) ' Lê milésimos (0,1) Case 1 lnXX = CInt(Mid(stInput, vtitN(1) + 1)) * 100 ' Lê milésimos (0,01) Case 2 lnXX = CInt(Mid(stInput, vtitN(1) + 1)) * 10 ' Lê milésimos (0,001) Case Else lnXX = CInt(Mid(stInput, vtitN(1) + 1)) End Select Else ' Lê segundos lnSS = CInt(Mid(stInput, vtitN(0) + 1)) End If End If ' Salva setTime lnMM, lnSS, lnXX, blNegative End If Exit Property ErrTreat: ln_Time = LN_INVALID_VALUE End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Propriedade em texto simples ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Property Get TextSimple() As String Dim stAux As String Dim lnMM As Long Dim lnSS As Long Dim lnXX As Long Dim blNegative As Boolean ' Pega valores GetTime lnMM, lnSS, lnXX, blNegative ' Se for negativo If blNegative Then ' Inicia retorno com negativo TextSimple = "-" Else ' Inicia retorno com positivo TextSimple = ST_INVALID_VALUE End If ' Coloca minutos no auxiliar stAux = CStr(lnMM) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_SECONDS_SIZE) stAux = "0" + stAux Wend ' Adiciona ao rertorno TextSimple = TextSimple + stAux ' Coloca segundos no auxiliar stAux = CStr(lnSS) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_MINUTES_SIZE) stAux = "0" + stAux Wend ' Adiciona ao rertorno TextSimple = TextSimple + CH_MINUTE_SEP + stAux ' Coloca milisegundos no auxiliar stAux = CStr(CLng(lnXX / 10)) ' Adiciona zeros se necessário While (Len(stAux) < LN_STR_HUNDRESECONDS_SIZE) stAux = "0" + stAux Wend ' Adiciona ao retorno TextSimple = TextSimple + CH_SEC_SEP + stAux End Property ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Procedimentos de criação e destruição do objeto ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Sub Class_Initialize() ' Inicia valores ln_Time = 0 End Sub