home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / mcvbehtp.zip / VBEHTP40.BAS < prev    next >
BASIC Source File  |  1996-05-16  |  17KB  |  486 lines

  1. Attribute VB_Name = "vbErrorHandler_bas"
  2. Option Explicit
  3.  
  4. Global Const VB_LNG_FRENCH = 1
  5. Global Const VB_LNG_DUTCH = 2
  6. Global Const VB_LNG_GERMAN = 3
  7. Global Const VB_LNG_ENGLISH = 4
  8. Global Const VB_LNG_ITALIAN = 5
  9. Global Const VB_LNG_SPANISH = 6
  10. Global Const VB_LNG_CATALAN = 7
  11. Global Const VB_LNG_POLISH = 8
  12.  
  13. Const MB_MESSAGE_LEFT = 0
  14.  
  15. #If Win16 Then
  16.  
  17. Declare Sub cPushID Lib "mcvb4016.dll" (IDArray As Integer, ByVal nID As Integer)
  18. Declare Sub cPopID Lib "mcvb4016.dll" (IDArray As Integer, ByVal nID As Integer)
  19. Declare Sub cPopLastID Lib "mcvb4016.dll" (IDArray As Integer)
  20. Declare Function cGetID Lib "mcvb4016.dll" (IDArray As Integer, ByVal nPosition As Integer) As Integer
  21. Declare Sub cClearID Lib "mcvb4016.dll" (IDArray As Integer)
  22. Declare Sub cChangeChars Lib "mcvb4016.dll" (Txt As String, CharSet As String, NewCharSet As String)
  23. Declare Function cGetIni Lib "mcvb4016.dll" (ByVal AppName As String, ByVal szItem As String, ByVal szDefault As String, ByVal InitFile As String) As String
  24. Declare Function cInsertBlocks Lib "mcvb4016.dll" (Txt As String, Insert As String) As String
  25. Declare Function cLngMsgBox Lib "mcvb4016.dll" (ByVal nLanguage As Integer, ByVal Message As String, ByVal Button As Long, ByVal Title As String) As Integer
  26. Declare Function cKillFileAll Lib "mcvb4016.dll" (ByVal lpFilename As String) As Integer
  27. Declare Function cTimerClose Lib "mcvb4016.dll" (ByVal TimerHandle As Integer) As Integer
  28. Declare Function cTimerOpen Lib "mcvb4016.dll" () As Integer
  29. Declare Function cTimerRead Lib "mcvb4016.dll" (ByVal TimerHandle As Integer) As Long
  30. Declare Function cTimerStart Lib "mcvb4016.dll" (ByVal TimerHandle As Integer) As Integer
  31.  
  32. #Else
  33.  
  34. Declare Sub cPushID Lib "mcvb4032.dll" (IDArray() As Integer, ByVal nID As Integer)
  35. Declare Sub cPopID Lib "mcvb4032.dll" (IDArray() As Integer, ByVal nID As Integer)
  36. Declare Sub cPopLastID Lib "mcvb4032.dll" (IDArray() As Integer)
  37. Declare Function cGetID Lib "mcvb4032.dll" (IDArray() As Integer, ByVal nPosition As Integer) As Integer
  38. Declare Sub cClearID Lib "mcvb4032.dll" (IDArray() As Integer)
  39. Declare Sub cChangeChars Lib "mcvb4032.dll" (Txt As String, CharSet As String, NewCharSet As String)
  40. Declare Function cGetIni Lib "mcvb4032.dll" (ByVal AppName As String, ByVal szItem As String, ByVal szDefault As String, ByVal InitFile As String) As String
  41. Declare Function cInsertBlocks Lib "mcvb4032.dll" (Txt As String, Insert As String) As String
  42. Declare Function cLngMsgBox Lib "mcvb4032.dll" (ByVal nLanguage As Integer, ByVal Message As String, ByVal Button As Long, ByVal Title As String) As Integer
  43. Declare Function cKillFileAll Lib "mcvb4032.dll" (ByVal lpFilename As String) As Integer
  44. Declare Function cTimerClose Lib "mcvb4032.dll" (ByVal TimerHandle As Integer) As Integer
  45. Declare Function cTimerOpen Lib "mcvb4032.dll" () As Integer
  46. Declare Function cTimerRead Lib "mcvb4032.dll" (ByVal TimerHandle As Integer) As Long
  47. Declare Function cTimerStart Lib "mcvb4032.dll" (ByVal TimerHandle As Integer) As Integer
  48.  
  49. #End If
  50.  
  51. 'Don't change any variables and their value below
  52.  
  53. Const ID_ITEMS = 16
  54.  
  55. Type tagERRORHANDLERtype
  56.    ModuleName                       As String * 256
  57.    RoutineHandle                    As String * 4
  58.    RoutineName                      As String * 76
  59.    CrLf                             As String * 2
  60. End Type
  61.  
  62. Type tagTRACERtype
  63.    StartStop                        As String * 1
  64.    RoutineHandle                    As Integer
  65. End Type
  66.  
  67. Type tagPROFILERtype
  68.    ModuleName                       As String * 256
  69.    RoutineHandle                    As String * 4
  70.    RoutineName                      As String * 76
  71.    TimeCounter                      As Long
  72.    TotalCall                        As Long
  73.    TotalTime                        As Long
  74.    MinimumTime                      As Long
  75.    MaximumTime                      As Long
  76.    Dummy                            As String * 10
  77.    CrLf                             As String * 2
  78. End Type
  79.  
  80. Dim TotalRoutines                   As Integer
  81. Dim ActualTrace                     As Long
  82. Dim OldStartRoutine                 As Integer
  83. Dim OldStopRoutine                  As Integer
  84.  
  85. Dim FileTR                          As String
  86. Dim FilePF                          As String
  87.  
  88. Dim chanFileTR                      As Integer
  89. Dim chanFilePF                      As Integer
  90.  
  91. Dim FileLNG                         As String
  92.  
  93. Dim FileHND                         As String
  94.  
  95. Dim FileLOG                         As String
  96.  
  97. Dim IDArray(0 To ID_ITEMS)          As Integer
  98.  
  99. Dim Language                        As Integer
  100. Dim AutoLog                         As Integer
  101. Dim WaitingTimeForReaction          As Integer
  102. Dim DefaultButton                   As Integer
  103. Dim DisplayOnline                   As Integer
  104. Dim TraceProfile                    As Integer
  105.  
  106. Dim TotalSameHandle                 As Long
  107. Dim LastHandle                      As Integer
  108. Dim ChanHandle                      As Integer
  109. Dim OldChanHandle                   As Integer
  110.  
  111. Dim tagERRORHANDLER                 As tagERRORHANDLERtype
  112. Dim tagTRACER                       As tagTRACERtype
  113. Dim tagPROFILER                     As tagPROFILERtype
  114.  
  115. Sub mcClearID()
  116.    #If Win16 Then
  117.       Call cClearID(IDArray(0))
  118.    #Else
  119.       Call cClearID(IDArray)
  120.    #End If
  121. End Sub
  122.  
  123. Function mcGetID(nPos As Integer)
  124.    #If Win16 Then
  125.       mcGetID = cGetID(IDArray(0), nPos)
  126.    #Else
  127.       mcGetID = cGetID(IDArray, nPos)
  128.    #End If
  129. End Function
  130.  
  131. Function mcGetLanguageID(LanguageID As Integer) As String
  132.  
  133.    Dim RetLanguage      As String
  134.  
  135.    Select Case LanguageID
  136.       Case VB_LNG_FRENCH
  137.          RetLanguage = "VFR"
  138.       Case VB_LNG_DUTCH
  139.          RetLanguage = "VNL"
  140.       Case VB_LNG_GERMAN
  141.          RetLanguage = "VDE"
  142.       Case VB_LNG_ENGLISH
  143.          RetLanguage = "VUK"
  144.       Case VB_LNG_ITALIAN
  145.          RetLanguage = "VIT"
  146.       Case VB_LNG_SPANISH
  147.          RetLanguage = "VSP"
  148.       Case VB_LNG_CATALAN
  149.          RetLanguage = "VCA"
  150.       Case VB_LNG_POLISH
  151.          RetLanguage = "VPO"
  152.       Case Else
  153.          RetLanguage = "VUK"
  154.    End Select
  155.    
  156.    If (LanguageID > 0) Then
  157.       Language = LanguageID
  158.    Else
  159.       Language = VB_LNG_ENGLISH
  160.    End If
  161.  
  162.    mcGetLanguageID = RetLanguage
  163.  
  164. End Function
  165.  
  166. Function mcIDErrorHandler(nErr As Integer) As Integer
  167.  
  168.    ' check if this a correct Error passed
  169.    If (nErr = 0) Then
  170.       'if no, resume next
  171.       mcIDErrorHandler = True
  172.       Exit Function
  173.    End If
  174.  
  175.    Dim RoutineCount     As Integer
  176.    Dim RoutineNumber    As Integer
  177.    Dim RoutineStack     As String
  178.    Dim TotalRoutines    As Integer
  179.    Dim BlankLines       As Integer
  180.    Dim Chan             As Integer
  181.    Dim StopExit         As Integer
  182.    Dim TimeOut          As Long
  183.    Dim ButtonsConfig    As Integer
  184.    Dim ErrorTitle       As String
  185.  
  186.    '  some initializations
  187.    RoutineStack = ""
  188.    TotalRoutines = 0
  189.    BlankLines = 0
  190.    StopExit = False
  191.    ButtonsConfig = 0
  192.    ErrorTitle = ""
  193.    RoutineStack = RoutineStack + mcReadText("0", "")
  194.    
  195.    ' find the next valid unused file number.
  196.    Chan = FreeFile
  197.  
  198.    ' open the file with the definition of each routines (file must be in the WINDOWS directory)
  199.    Close #Chan
  200.    Open FileHND For Random Shared As #Chan Len = Len(tagERRORHANDLER)
  201.  
  202.    ' get the stack of the routines
  203.    For RoutineCount = 0 To ID_ITEMS
  204.       ' get the number of the routine
  205.       RoutineNumber = mcGetID(RoutineCount)
  206.       ' if there a valid routine number
  207.       If (RoutineNumber > 0) Then
  208.          ' yes, read the definition of the routine
  209.          Get #Chan, RoutineNumber, tagERRORHANDLER
  210.          ' form the stack of the routines founden to display
  211.          RoutineStack = RoutineStack + Left$(tagERRORHANDLER.ModuleName + Space$(12), 14) + Chr$(9) + tagERRORHANDLER.RoutineHandle + Chr$(9) + Trim$(tagERRORHANDLER.RoutineName) + Chr$(13)
  212.          ' count the routines to display
  213.          TotalRoutines = TotalRoutines + 1
  214.       Else
  215.          ' no, exit from reading the stack
  216.          Exit For
  217.       End If
  218.    Next RoutineCount
  219.  
  220.    ' close the open file
  221.    Close #Chan
  222.  
  223.    ' check if the default button must be activated
  224.    If (DefaultButton = True) Then
  225.       ' yes, RETRY and CANCEL with RETRY is the default
  226.       ButtonsConfig = 5 Or 0
  227.    Else
  228.       ' no, RETRY and CANCEL with CANCEL is the default
  229.       ButtonsConfig = 5 Or 256
  230.       ' yes, add text for RETRY after timeout or action
  231.       RoutineStack = RoutineStack & Chr$(13) & Chr$(13) & "program will be stopped"
  232.    End If
  233.  
  234.    ' set the error title
  235.    ErrorTitle = mcReadText("1", nErr & "~" & Error$(nErr))
  236.  
  237.    ' check if one routine has been founded
  238.    If (Len(RoutineStack) > 0) Then
  239.       ' check the time out
  240.       TimeOut = WaitingTimeForReaction * (163840 Or 524288)
  241.       ' display remaining blank lines
  242.       BlankLines = (8 - TotalRoutines) - (TimeOut = 0)
  243.       For RoutineCount = 0 To BlankLines
  244.          RoutineStack = RoutineStack + Chr$(13)
  245.       Next RoutineCount
  246.       ' add some text for management
  247.       RoutineStack = RoutineStack & mcReadText("2", "")
  248.       ' check if a timeout must be used
  249.       If (TimeOut <> 0) Then
  250.          ' yes, add text depending of the default button
  251.          RoutineStack = RoutineStack & mcReadText("3", "") & " "
  252.          ' if default is RETRY then display 'continue' else 'stop'
  253.          If (DefaultButton = True) Then
  254.             RoutineStack = RoutineStack & mcReadText("4", "")
  255.          Else
  256.             RoutineStack = RoutineStack & mcReadText("5", "")
  257.          End If
  258.       End If
  259.       ' display the error message box
  260.       StopExit = (cLngMsgBox(Language, RoutineStack, MB_MESSAGE_LEFT Or TimeOut Or ButtonsConfig Or 16, ErrorTitle) = 2)
  261.       ' yield process
  262.       DoEvents
  263.    End If
  264.  
  265.    ' check if an auto logging must be performed
  266.    If (AutoLog = True) Then
  267.  
  268.       ' open the logging file in append mode
  269.       Close #Chan
  270.       Open FileLOG For Append Shared As #Chan
  271.  
  272.       ' save the error and his description
  273.       Print #Chan, ErrorTitle; " "; mcReadText("6", Date$ & "~" & Time$)
  274.       Print #Chan, ""
  275.       ' save the full stack name of each routines founden
  276.       Print #Chan, RoutineStack
  277.       Print #Chan, ""
  278.       ' check if the CANCEL button pushed or TimeOut
  279.       If (StopExit = True) Then
  280.          ' yes stop by operator, save text for CANCEL
  281.          Print #Chan, mcReadText("7", "")
  282.       Else
  283.          ' no, retry by operator, save text for RETRY
  284.          Print #Chan, mcReadText("8", "")
  285.       End If
  286.       ' save separator
  287.       Print #Chan, String$(78, "-")
  288.  
  289.       ' close the file
  290.       Close #Chan
  291.  
  292.    End If
  293.  
  294.    ' if stop the program the END the application
  295.    If (StopExit = True) Then End
  296.  
  297.    ' no stop, resumes to next line in the main application
  298.    mcIDErrorHandler = True
  299.  
  300. End Function
  301.  
  302. Sub mcOnlineDisplay(ID As Integer)
  303.  
  304.    Dim ActualLine    As String
  305.  
  306.    If (ChanHandle = -1) Then
  307.  
  308.       ' close the old chan if more than 1 mcInitID is called
  309.       If (OldChanHandle <> -1) Then Close #OldChanHandle
  310.  
  311.       ' find the next valid unused file number.
  312.       ChanHandle = FreeFile
  313.  
  314.       ' open the file with the definition of each routines (file must be in the WINDOWS directory)
  315.       Close #ChanHandle
  316.       Open FileHND For Random Shared As #ChanHandle Len = Len(tagERRORHANDLER)
  317.  
  318.       ' save the handle
  319.       OldChanHandle = ChanHandle
  320.  
  321.    End If
  322.  
  323.    ' read the handle
  324.    Get #ChanHandle, ID, tagERRORHANDLER
  325.  
  326.    If (LastHandle = ID) Then
  327.       TotalSameHandle = TotalSameHandle + 1
  328.    Else
  329.       If (frmDisplayOnline.lstOnline.ListIndex > -1) Then
  330.          ActualLine = frmDisplayOnline.lstOnline.List(frmDisplayOnline.lstOnline.ListIndex)
  331.          frmDisplayOnline.lstOnline.List(frmDisplayOnline.lstOnline.ListIndex) = TotalSameHandle & Mid$(ActualLine, InStr(ActualLine, Chr$(9)))
  332.       End If
  333.       TotalSameHandle = 1
  334.    End If
  335.  
  336.    frmDisplayOnline.lblCounter = TotalSameHandle
  337.    frmDisplayOnline.lblHandle = ID
  338.  
  339.    If (LastHandle <> ID) Then
  340.       frmDisplayOnline.lstOnline.AddItem TotalSameHandle & Chr$(9) & Trim$(tagERRORHANDLER.RoutineHandle) & Chr$(9) & Trim$(tagERRORHANDLER.ModuleName) & Chr$(9) & Trim$(tagERRORHANDLER.RoutineName)
  341.       If (frmDisplayOnline.lstOnline.ListCount > 25) Then frmDisplayOnline.lstOnline.RemoveItem 0
  342.       frmDisplayOnline.lstOnline.ListIndex = frmDisplayOnline.lstOnline.NewIndex
  343.    End If
  344.  
  345.    LastHandle = ID
  346.  
  347.    DoEvents
  348.  
  349. End Sub
  350.  
  351. Sub mcPopID(ID As Integer)
  352.    #If Win16 Then
  353.       Call cPopID(IDArray(0), ID)
  354.    #Else
  355.       Call cPopID(IDArray, ID)
  356.    #End If
  357. End Sub
  358.  
  359. Sub mcPopLastID(WhichManagement As Integer, RoutineNumber As Integer)
  360.    If ((Abs(WhichManagement) = 2) Or (Abs(WhichManagement) = 3)) Then Call mcStopTracer(RoutineNumber)
  361.    #If Win16 Then
  362.       Call cPopLastID(IDArray(0))
  363.    #Else
  364.       Call cPopLastID(IDArray)
  365.    #End If
  366. End Sub
  367.  
  368. Sub mcPushID(ID As Integer)
  369.    #If Win16 Then
  370.       Call cPushID(IDArray(0), ID)
  371.    #Else
  372.       Call cPushID(IDArray, ID)
  373.    #End If
  374.    If (DisplayOnline = True) Then Call mcOnlineDisplay(ID)
  375. End Sub
  376.  
  377. Function mcReadText(TextOrder As String, InsertText As String) As String
  378.  
  379.    Dim Tmp              As String
  380.    Dim BasisText        As String
  381.  
  382.    ' read the text in the language file
  383.    BasisText = cGetIni("mcvbehtp", TextOrder, "?", FileLNG)
  384.    
  385.    ' insert some text if any
  386.    Tmp = cInsertBlocks(BasisText, InsertText)
  387.  
  388.    ' change all º by a CR and all ú by TAB
  389.    Call cChangeChars(Tmp, "ºú", Chr$(13) + Chr$(9))
  390.  
  391.    mcReadText = Tmp
  392.  
  393. End Function
  394.  
  395. Sub mcStartTracer(RoutineNumber As Integer)
  396.  
  397.    Dim TimerCounter  As Integer
  398.    Dim Status        As Integer
  399.  
  400.    ' check if the routine number is not outside the limits
  401.    If ((RoutineNumber < 1) Or (RoutineNumber > TotalRoutines)) Then Exit Sub
  402.  
  403.    ' check if this is the same routine
  404.    If (OldStartRoutine <> RoutineNumber) Then
  405.       ' increment the trace number
  406.       ActualTrace = ActualTrace + 1
  407.       ' prepare the trace information
  408.       tagTRACER.StartStop = ">"
  409.       tagTRACER.RoutineHandle = RoutineNumber
  410.       ' save the trace information
  411.       Put #chanFileTR, ActualTrace, tagTRACER
  412.    End If
  413.  
  414.    ' save the old routine
  415.    OldStartRoutine = RoutineNumber
  416.  
  417.    ' read the record associated with the routine number
  418.    Get #chanFilePF, RoutineNumber, tagPROFILER
  419.  
  420.    ' open a timer
  421.    TimerCounter = cTimerOpen()
  422.    ' save the handle of the new timer
  423.    tagPROFILER.TimeCounter = TimerCounter
  424.    ' increment the number of calls
  425.    tagPROFILER.TotalCall = tagPROFILER.TotalCall + 1
  426.  
  427.    ' save the record associated with the routine number
  428.    Put #chanFilePF, RoutineNumber, tagPROFILER
  429.  
  430.    ' start the timer
  431.    Status = cTimerStart(TimerCounter)
  432.  
  433. End Sub
  434.  
  435. Sub mcStopTracer(RoutineNumber As Integer)
  436.  
  437.    Dim TimerCounter  As Integer
  438.    Dim TimeElapsed   As Long
  439.    Dim Status        As Integer
  440.  
  441.    ' check if the routine number is not outside the limits
  442.    If ((RoutineNumber < 1) Or (RoutineNumber > TotalRoutines)) Then Exit Sub
  443.  
  444.    ' check if this is the same routine
  445.    If (OldStopRoutine <> RoutineNumber) Then
  446.       ' increment the trace number
  447.       ActualTrace = ActualTrace + 1
  448.       ' prepare the trace information
  449.       tagTRACER.StartStop = "<"
  450.       tagTRACER.RoutineHandle = RoutineNumber
  451.       ' save the trace information
  452.       Put #chanFileTR, ActualTrace, tagTRACER
  453.    End If
  454.  
  455.    ' save the old routine
  456.    OldStopRoutine = RoutineNumber
  457.  
  458.    ' read the record associated with the routine number
  459.    Get #chanFilePF, RoutineNumber, tagPROFILER
  460.  
  461.    ' check if the timer is valid
  462.    If (tagPROFILER.TimeCounter > 0) Then
  463.       ' computes the elapsed time
  464.       TimeElapsed = cTimerRead(tagPROFILER.TimeCounter)
  465.       ' add the elapsed time
  466.       tagPROFILER.TotalTime = tagPROFILER.TotalTime + TimeElapsed
  467.       ' check for the minimum time
  468.       If (TimeElapsed < tagPROFILER.MinimumTime) Then tagPROFILER.MinimumTime = TimeElapsed
  469.       ' check for the minimum time
  470.       If (TimeElapsed > tagPROFILER.MaximumTime) Then tagPROFILER.MaximumTime = TimeElapsed
  471.    End If
  472.  
  473.    ' save the record associated with the routine number
  474.    Put #chanFilePF, RoutineNumber, tagPROFILER
  475.  
  476.    ' close the associated timer
  477.    Status = cTimerClose(tagPROFILER.TimeCounter)
  478.  
  479. End Sub
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.