0% found this document useful (0 votes)
129 views5 pages

Microsoft Visual Basic For Applications PDF

This document contains code for initializing and controlling a calculation add-in. It defines constants, variables, and functions related to checking authorization status, handling different authorization scenarios, and controlling the calculation engine. The code handles starting the calculation, checking for valid authorization, displaying authorization dialogs, and controlling the user interface during calculation events.

Uploaded by

Thai Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views5 pages

Microsoft Visual Basic For Applications PDF

This document contains code for initializing and controlling a calculation add-in. It defines constants, variables, and functions related to checking authorization status, handling different authorization scenarios, and controlling the calculation engine. The code handles starting the calculation, checking for valid authorization, displaying authorization dialogs, and controlling the user interface during calculation events.

Uploaded by

Thai Trang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MTC_Main - 1

Option Explicit
Private Const MTC_MODULE_VER = "1.18"

Private Const MTC_VER_MAJOR = "1" '1 znak HEXA


Private Const MTC_VER_MINOR = "01" '2 znaky DECIMAL

Private Const MTC_SERVICE_ADDIN = "MITCALC.XLA"


Private Const MTC_SERVICE_FUNCTION = "MTC_Service"

Private IS_AUTHORIZED As Boolean


Private IS_VALID As Boolean
Private IS_DEMO As Boolean
Private IS_VIEWMODE As Boolean
Private IS_OFF_EVENT As Boolean
Private IS_START As Boolean

Public IS_NOT_HKLM As Boolean


Public MTC_AUT_ERR As Integer

Public AuthDialogType As String 'obsahuje jeden ze znaku 1,2,3,4,5,6 a musi ji naplnit pred zobraze
nim
Public AuthDialogDays As Integer 'obsahuje cislo, ktere bude zapsano do textu autorizacniho dialogu
Public CustomerName As String 'obsahuje jmeno zakaznika z autorizacniho hesla
Public IsAuthFinish As Boolean 'ridici promenna pro cyklus registrace
Public AuthDialogStart As Boolean 'ridici promenna rikajici zda dialog volan pri start nebo z option

Public Const ROW_HEIGHT As Double = 15.75

Private Function MTC_ControlDLLVersion(ByVal DLLVersion As String) As Boolean


On Error Resume Next
DLLVersion = Trim(DLLVersion)
If ("000" = DLLVersion) Or MTC_VER_MAJOR = Left(DLLVersion, 1) Then
MTC_ControlDLLVersion = True
Else
MTC_ControlDLLVersion = False
End If
End Function

Private Sub MTC_CheckStart()


On Error Resume Next

Dim IsView As Boolean, NoTimeVer As Boolean


Dim PWD_Status As Integer, DaysToEnd As Integer, DLLVersion As String

IS_START = True
IsView = False
If LoadMTCDLL Then
PWD_Status = VB_MTC_GetPWDStatus(CustomerName, DaysToEnd, DLLVersion)
NoTimeVer = (45000# < (Date + DaysToEnd))
Select Case PWD_Status
Case 2
If ((0 > DaysToEnd) And (False = NoTimeVer)) Or (False = MTC_ControlDLLVersion(DLLVersion)) Th
en IsView = True
Case 1
If (0 > DaysToEnd) Or (30 < DaysToEnd) Then IsView = True
Case Else
IsView = True
End Select
Call FreeMTCDLL
Else
IsView = True
End If

If IsView Then
IS_VIEWMODE = True
Call BackupDataForViewMode
Call ShowMsg("MSG_BadStart")
End If
End Sub

Private Sub Registration(Optional ByVal void As Boolean = True)


Dim PWD_Status As Integer, DaysToEnd As Integer, DLLVersion As String
Dim CtrlDLLVer As Boolean, NoTimeVer As Boolean
MTC_Main - 2

IsAuthFinish = False

While Not IsAuthFinish


PWD_Status = VB_MTC_GetPWDStatus(CustomerName, DaysToEnd, DLLVersion)

Select Case PWD_Status


Case 2 'vracen priznak pro FULL verzi
IS_AUTHORIZED = True
IS_VIEWMODE = False
IS_DEMO = False
CtrlDLLVer = MTC_ControlDLLVersion(DLLVersion)
NoTimeVer = (45000# < (Date + DaysToEnd))
If AuthDialogStart And CtrlDLLVer And ((DaysToEnd > 30) Or NoTimeVer) Then
Exit Sub
Else
If NoTimeVer And CtrlDLLVer Then
AuthDialogType = 0
ElseIf (DaysToEnd > 0) And CtrlDLLVer Then
AuthDialogType = 1: AuthDialogDays = DaysToEnd
Else
If "" = Trim(CustomerName) Then
IS_VIEWMODE = True
AuthDialogType = 5
ElseIf Not CtrlDLLVer Then
IS_VIEWMODE = True
AuthDialogType = 6
MTC_AUT_ERR = 99
Else
IS_VIEWMODE = True
AuthDialogType = 2
End If
End If
End If

Case 1 'vracen priznak pro DEMO verzi


IS_AUTHORIZED = False
IS_VIEWMODE = False
If DaysToEnd > 0 And DaysToEnd <= 30 Then
IS_DEMO = True
AuthDialogType = 3: AuthDialogDays = DaysToEnd
Else
If DaysToEnd > 30 Then Call ShowMsg("MSG_ChDate", WARNING_BOX_STYLE)
IS_DEMO = False: IS_VIEWMODE = True
AuthDialogType = 4
End If

Case Else 'vracen chybny priznak


IS_DEMO = False: IS_VIEWMODE = True
AuthDialogType = 6

End Select

IsAuthFinish = True
frmAuthorization.Show
Wend
End Sub

Public Sub MTC_StartMITCalc(Optional ByVal void As Boolean = True)


On Error GoTo Err_MSSP

If False = AddInInit(MTC_SERVICE_ADDIN) Then


Call ShowMsg("MSG_NoServiceAddIn", WARNING_BOX_STYLE)
Exit Sub
End If

Call Application.Run(MTC_SERVICE_ADDIN & "!" & MTC_SERVICE_FUNCTION, (CALC_NAME))

Exit Sub

Err_MSSP:
Call MsgBox(Error(Err.Number), WARNING_BOX_STYLE, Err.Source)
End Sub
MTC_Main - 3

Public Sub MTC_StartHelp(Optional ByVal void As Boolean = True)


On Error Resume Next
Call MTC_SheetControl
Call StartHandbook
End Sub

Public Sub MTC_StartAuthorization(Optional ByVal void As Boolean = True)


On Error Resume Next
Call MTC_SheetControl
AuthDialogStart = False
Call Authorization
End Sub

Public Sub MTC_WorkBookSaving(ByVal SaveAsUI As Boolean)


On Error Resume Next

Call FillProjectData

If Not SaveAsUI Then


Call WriteRegistryFlagSave

Call WriteRegistryLanguage
End If
End Sub

Public Sub MTC_SheetChange(Optional ByVal void As Boolean = True)


On Error Resume Next

If IS_VALID Then Exit Sub


If False = IS_START Then Call MTC_CheckStart

If False = IS_VIEWMODE Then 'Registrovana verze


Call IntegrityCheck
Else 'View verze
Call ViewModeRollBack
End If
If Range("S_HRI00").Value Then Call FillProjectData
End Sub

Public Sub MTC_SheetCalculate(ByVal Sh As Object)


On Error GoTo Err_SHCAL

Dim i As Long, J As Long, k As Long


Dim Max_row As Long
Dim Command As String
Dim CommandString As String
Dim CommandFlag As Boolean
Dim IsProtect As Boolean

If ThisWorkbook.Name <> ActiveWorkbook.Name Then Exit Sub

IsProtect = ActiveSheet.ProtectContents
If IsProtect Then Call SwitchUserInterfaceOnly(True)

Max_row = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count


Call HelpFunctionSet(False) 'zakaze reakci na udalost

i = ActiveSheet.UsedRange.Row
Command = ReadCellStringValue(ActiveSheet.Cells(i, 1))

While Command <> "END" And i < Max_row


If Command <> "" Then
CommandString = ReadCellFormula(ActiveSheet.Cells(i, 1))
CommandFlag = ReadCellBoolValue(ActiveSheet.Cells(i, 2))

Select Case Command


Case "CELLTRANSMIT"
If CommandFlag Then Call CommandCellTransmitForm(CommandString)
Case "CELLTRANSMITVAL"
If CommandFlag Then Call CommandCellTransmitVal(CommandString)
Case "CELLTRANSMITFORM"
If CommandFlag Then Call CommandCellTransmitForm(CommandString)
MTC_Main - 4

Case "ROWSHIDELIST"
Call CommandRowsHideList(CommandString, CommandFlag)
Case "ROWSHIDERANGE"
Call CommandRowsHideRange(CommandString, CommandFlag)
End Select
End If

i = i + 1
Command = ReadCellStringValue(ActiveSheet.Cells(i, 1))
Wend

If IsProtect Then Call SwitchUserInterfaceOnly(False)


Call HelpFunctionSet(True) 'vrati priznak pro vyvolavani udalosti

If Range("S_HRI00").Value Then Call FillProjectData


Exit Sub

Err_SHCAL:
If IsProtect Then Call SwitchUserInterfaceOnly(False)
Call HelpFunctionSet(True) 'vrati priznak pro vyvolavani udalosti
#If DEBUG_MODE Then
Call ShowDebugMsg("Problem into sheet calculate event")
#End If
End Sub

Public Sub MTC_SheetControl(Optional ByVal void As Boolean = True)


On Error Resume Next

If (False = Application.EnableEvents) Then Application.EnableEvents = True


IS_OFF_EVENT = False
End Sub

Public Sub HelpFunctionSet(ByVal bMode As Boolean)


On Error Resume Next

IS_OFF_EVENT = False
Application.EnableEvents = bMode
If (False = Application.EnableEvents) Then IS_OFF_EVENT = True
End Sub

Public Sub HelpFunctionTest(Optional ByVal void As Boolean = True)


On Error Resume Next

If (False = IS_VIEWMODE) And (False = IS_DEMO) Then Exit Sub

If (False = Application.EnableEvents) And (False = IS_OFF_EVENT) Then


Application.EnableEvents = True
End If
End Sub

Public Function IsCalcDemo(Optional ByVal void As Boolean = True) As Boolean


IsCalcDemo = IS_DEMO
End Function

Public Function IsCalcView(Optional ByVal void As Boolean = True) As Boolean


IsCalcView = IS_VIEWMODE
End Function

Public Function GetCalcVersion() As String


On Error Resume Next

GetCalcVersion = MTC_VER_MAJOR & MTC_VER_MINOR


End Function

Public Function GetCalcError() As String


On Error Resume Next

Dim sCalcID$, sErrID$

GetCalcError = ""
If "A" = MTC_VER_MAJOR Then sCalcID = MTC_VER_MINOR Else sCalcID = "00"

Select Case MTC_AUT_ERR


MTC_Main - 5

Case 7:
If CtrlInst(sErrID) Then GetCalcError = " [ERROR " & sErrID & sCalcID & "]"
Exit Function

Case 11, 13, 15, 21 To 26, 41, 43, 45, 51, 53, 55, 99:
sErrID = Trim(Str(MTC_AUT_ERR))

Case Else:
Exit Function
End Select

GetCalcError = " [" & sErrID & sCalcID & "]"


End Function

You might also like