Attribute VB_Name = "GlobalVars"
Option Explicit

Public Type denom
    Valor As Long
    Inhibit As Byte
    max As Integer
    low As Byte
    current As Integer
End Type

Public MainCC As String
Public CurCC As String
Public Monedes As String
Public Bitllets As String
Public CCC() As denom
Public LBCCC As Integer
Public UBCCC As Integer
Public CCN() As denom
Public LBCCN As Integer
Public UBCCN As Integer
Public CK As CKeeperLibV2.CKeeper
Public CIP As String
Public CPM As Long
Public CPO As Long
Public CS As Long
Public CTC As Boolean
Public CCF As Byte
Public CDSP As Long
Public CMode As CKeeperLibV2.ConnTypes

Public Function SetCC(ByVal CC As String) As Boolean
    Dim valu As Variant
    Dim inh As Variant
    Dim max As Variant
    Dim low As Variant
    Dim sWrk As String
    Dim i As Integer
    Dim blow As Byte
    
    CurCC = CC
    If Not CK.GetCCDenominations(CurCC, Monedes, Bitllets) Then
        'MsgBox "GetCCDenominations falla"
        Exit Function
    End If
    ReDim CCC(0)
    LBCCC = LBound(CCC)
    UBCCC = UBound(CCC)
    ReDim CCN(0)
    LBCCN = LBound(CCN)
    UBCCN = UBound(CCN)
    If CurCC = MainCC Then
        If Len(Monedes) > 0 Then
            valu = Split(Monedes, ",")
            ReDim CCC(UBound(valu))
            LBCCC = LBound(CCC)
            UBCCC = UBound(CCC)
            If Not CK.GetInhibitState(CurCC, Monedes, sWrk) Then
                'MsgBox "GetInhibitState falla"
                Exit Function
            End If
            inh = Split(sWrk, ",")
            If Not CK.GetMaxLevel(Monedes, sWrk) Then
                'MsgBox "GetMaxLevel falla"
                Exit Function
            End If
            max = Split(sWrk, ",")
            blow = CK.CoinsLowLevel
            For i = LBound(valu) To UBound(valu)
                CCC(i).Valor = CLng(valu(i))
                CCC(i).Inhibit = CByte(inh(i))
                CCC(i).max = CInt(max(i))
                CCC(i).low = blow
                CCC(i).current = 0
            Next i
        End If
    End If
    If Len(Bitllets) > 0 Then
        valu = Split(Bitllets, ",")
        ReDim CCN(UBound(valu))
        LBCCN = LBound(CCN)
        UBCCN = UBound(CCN)
        If Not CK.GetInhibitState(CurCC, Bitllets, sWrk) Then
            'MsgBox "GetInhibitState falla"
            Exit Function
        End If
        inh = Split(sWrk, ",")
        If (CurCC = MainCC) Then
            If Not CK.GetMaxLevel(Bitllets, sWrk) Then
                'MsgBox "GetMaxLevel falla"
                Exit Function
            End If
            max = Split(sWrk, ",")
            If Not CK.GetLowLevelNotes(Bitllets, sWrk) Then
                'MsgBox "GetLowLevelNotes falla"
                Exit Function
            End If
            low = Split(sWrk, ",")
        End If
        For i = LBound(valu) To UBound(valu)
            CCN(i).Valor = CLng(valu(i))
            CCN(i).Inhibit = CByte(inh(i))
            If CurCC = MainCC Then
                CCN(i).max = CInt(max(i))
                CCN(i).low = CByte(low(i))
            Else
                CCN(i).max = 0
                CCN(i).low = 0
            End If
        Next i
    End If
    SetCC = True
End Function

Public Function LoadCurrentValues() As Boolean
    Dim curr As Variant
    Dim sWrk As String
    Dim i As Integer
    
    If CurCC = MainCC Then
        If Len(Monedes) > 0 Then
            If Not CK.GetCurrentLevel(Monedes, sWrk) Then
                'MsgBox "GetCurrentLevel falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCC To UBCCC
                CCC(i).current = CInt(curr(i))
            Next i
        End If
        If Len(Bitllets) > 0 Then
            If Not CK.GetCurrentLevel(Bitllets, sWrk) Then
                'MsgBox "GetCurrentLevel falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCN To UBCCN
                CCN(i).current = CInt(curr(i))
            Next i
        End If
    Else
        If Len(Bitllets) > 0 Then
            For i = LBCCN To UBCCN
                CCN(i).current = 0
            Next i
        End If
    End If
    LoadCurrentValues = True
End Function

Public Function LoadMaxLevels() As Boolean
    Dim curr As Variant
    Dim sWrk As String
    Dim i As Integer
    
    If CurCC = MainCC Then
        If Len(Monedes) > 0 Then
            If Not CK.GetMaxLevel(Monedes, sWrk) Then
                'MsgBox "GetCurrentLevel falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCC To UBCCC
                CCC(i).max = CInt(curr(i))
            Next i
        End If
        If Len(Bitllets) > 0 Then
            If Not CK.GetMaxLevel(Bitllets, sWrk) Then
                'MsgBox "GetCurrentLevel falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCN To UBCCN
                CCN(i).max = CInt(curr(i))
            Next i
        End If
    Else
        For i = LBCCN To UBCCN
            CCN(i).max = 0
        Next i
    End If
    LoadMaxLevels = True
End Function

Public Function LoadLowLevels() As Boolean
    Dim curr As Variant
    Dim sWrk As String
    Dim i As Integer
    Dim low As Byte
    
    If CurCC = MainCC Then
        If Len(Monedes) > 0 Then
            low = CK.CoinsLowLevel
            For i = LBCCC To UBCCC
                CCC(i).low = low
            Next i
        End If
        If Len(Bitllets) > 0 Then
            If Not CK.GetLowLevelNotes(Bitllets, sWrk) Then
                'MsgBox "GetLowLevelNotes falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCN To UBCCN
                CCN(i).low = CByte(curr(i))
            Next i
        End If
    Else
        For i = LBCCN To UBCCN
            CCN(i).low = 0
        Next i
    End If
    LoadLowLevels = True
End Function

Public Function LoadInhibits() As Boolean
    Dim curr As Variant
    Dim sWrk As String
    Dim i As Integer
    'Dim low As Byte
    
    If CurCC = MainCC Then
        If Len(Monedes) > 0 Then
            If Not CK.GetInhibitState(CurCC, Monedes, sWrk) Then
                'MsgBox "GetCoinsLowLevel falla"
                Exit Function
            End If
            curr = Split(sWrk, ",")
            For i = LBCCC To UBCCC
                CCC(i).Inhibit = CByte(curr(i))
            Next i
        End If
    End If
    If Len(Bitllets) > 0 Then
        If Not CK.GetInhibitState(CurCC, Bitllets, sWrk) Then
            'MsgBox "GetLowLevelNotes falla"
            Exit Function
        End If
        curr = Split(sWrk, ",")
        For i = LBCCN To UBCCN
            CCN(i).Inhibit = CByte(curr(i))
        Next i
    End If
    LoadInhibits = True
End Function

Public Sub Main()
    ObtenirTamanyUtilPantalla
    Set CK = New CKeeperLibV2.CKeeper
    frmConnect.Show
    'If CK.State > 0 Then
    '    Principal.Show
    '    Exit Sub
    'End If
    'End
End Sub
